Revision control

Copy as Markdown

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package mozilla.lockbox.extensions
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.os.Build
/**
* Checks for availability of network.
*
* For devices above [Build.VERSION_CODES.M] it even checks if there's internet flowing through it or not.
* */
fun ConnectivityManager.isOnline(network: Network): Boolean {
return getNetworkCapabilities(network)?.let {
it.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) &&
it.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
} ?: false
}