aws-amplify / aws-amplify/amplify-android
Enhance network connection status in ReachabilityMonitor of Datastore
- Dominant language
- Java
- Stars
- 287
- Forks
- 132
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 45
Description
### Before opening, please confirm:
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-android/issues?q=is%3Aissue+) and [discussions](https://github.com/aws-amplify/amplify-android/discussions).
### Language and Async Model
Java, Kotlin, RxJava
### Amplify Categories
DataStore
### Gradle script dependencies
```groovy
// Put output below this line
api("com.amplifyframework:aws-api:2.14.11")
api("com.amplifyframework:core:2.14.11")
api("com.amplifyframework:aws-datastore:2.14.11")
api("com.amplifyframework:rxbindings:2.14.11")
```
### Environment information
```
# Put output below this line
8.3.0
```
### Please include any relevant guides or documentation you're referencing
ReachabilityMonitor detect network connection but it doesn't check whether it is connect
### Describe the feature request
The original commit https://github.com/aws-amplify/amplify-android/commit/dfb5b55f0b6a9f4d3b0ab3d55bb610765a824f1b#diff-8dd0015f3eddee483b38c9b008f9db975c9840c2709abbfca6a783f1b9baa8f4 adds ReachabilityMonitorImpl with a DefaultConnectivityProvider which indicates there is network available:
```
override val hasActiveNetwork: Boolean
get() = connectivityManager?.let { it.activeNetwork != null }
?: run {
throw DataStoreException(
"ReachabilityMonitor has not been configured.",
"Call ReachabilityMonitor.configure() before calling ReachabilityMonitor.getObservable()"
)
}
```
However, even when network is active, it may not connect to internet. Since sync operation in Datastore depends on ReachabilityMonitor to provide network status, it could lead to too many sync attempts when internet is not available but there is still active network.
Please kindly let me know if ReachabilityMonitor is lacking or serves a distinct purpose in Datastore. Possible enhancement I could think of:
- Instead of checking activeNetwork, connectivity provider could retrieve getNetworkCapabilities and check the network capability is valid.
- Network callback should have an extra [onCapabilitiesChanged()
- A more fine grained detail to support different Android SDK version for network checking.
Resources:
- https://developer.android.com/training/monitoring-device-state/connectivity-status-type
- https://medium.com/@veniamin.vynohradov/monitoring-internet-connection-state-in-android-da7ad915b5e5
- https://www.youtube.com/watch?v=TzV0oCRDNfM
### Initialization steps (if applicable)
_No response_
### Code Snippet
```java
// Put your code below this line.
```
### amplifyconfiguration.json
_No response_
### GraphQL Schema
```graphql
// Put your schema below this line
```
### Additional information and screenshots
_No response_
Contributor guide
Research direction
Start with ReachabilityMonitorImpl and its DefaultConnectivityProvider, then trace how activeNetwork and the network callback feed ReachabilityMonitor.getObservable() and DataStore sync. Review the linked Android connectivity guidance and determine the required SDK-specific behavior; done means sync is not repeatedly attempted when a network exists without usable internet connectivity.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- mobile-dev, networking
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100