Skip to content

Commit

Permalink
treat metered wi-fis as mobile data (fixes #1699)
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Jan 26, 2020
1 parent 0286d5e commit b12c754
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,12 @@ class QuestAutoSyncer @Inject constructor(

private fun updateConnectionState(): Boolean {
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val info = connectivityManager.activeNetworkInfo
val info = connectivityManager.activeNetworkInfo ?: return false

val newIsConnected = info?.isConnected == true
val newIsWifi = newIsConnected && info?.type == ConnectivityManager.TYPE_WIFI
val newIsConnected = info.isConnected
// metered (usually ad-hoc hotspots) do not count as proper wifis
val isMetered = connectivityManager.isActiveNetworkMetered
val newIsWifi = newIsConnected && info.type == ConnectivityManager.TYPE_WIFI && !isMetered

val result = newIsConnected != isConnected || newIsWifi != isWifi

Expand Down

0 comments on commit b12c754

Please sign in to comment.