aws-amplify / amplify-android

The fastest and easiest way to use AWS from your Android app.
https://docs.amplify.aws/lib/q/platform/android/
Apache License 2.0
243 stars 114 forks source link

Enhance network connection status in ReachabilityMonitor of Datastore #2738

Open aladine opened 5 months ago

aladine commented 5 months ago

Before opening, please confirm:

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:

Resources:

Initialization steps (if applicable)

No response

Code Snippet

// 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

mattcreaser commented 5 months ago

Solid suggestion @aladine. We'll look at getting this prioritized, but I also encourage you to give it a shot and open a PR yourself!