mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-23 18:15:30 +00:00
Fix network capabilities
This commit is contained in:
parent
f989756b93
commit
a4a734458b
@ -1,14 +1,13 @@
|
|||||||
package com.topjohnwu.magisk.core.utils.net
|
package com.topjohnwu.magisk.core.utils.net
|
||||||
|
|
||||||
import android.annotation.TargetApi
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.net.Network
|
import android.net.Network
|
||||||
import android.net.NetworkCapabilities
|
import android.net.NetworkCapabilities
|
||||||
import android.net.NetworkRequest
|
import android.net.NetworkRequest
|
||||||
|
import android.os.Build
|
||||||
import androidx.collection.ArraySet
|
import androidx.collection.ArraySet
|
||||||
|
|
||||||
@TargetApi(21)
|
|
||||||
open class LollipopNetworkObserver(
|
open class LollipopNetworkObserver(
|
||||||
context: Context,
|
context: Context,
|
||||||
callback: ConnectionCallback
|
callback: ConnectionCallback
|
||||||
@ -17,10 +16,13 @@ open class LollipopNetworkObserver(
|
|||||||
private val networkCallback = NetCallback()
|
private val networkCallback = NetCallback()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val request = NetworkRequest.Builder()
|
val builder = NetworkRequest.Builder()
|
||||||
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
.build()
|
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
|
||||||
manager.registerNetworkCallback(request, networkCallback)
|
} else {
|
||||||
|
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||||
|
}
|
||||||
|
manager.registerNetworkCallback(builder.build(), networkCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
@file:Suppress("DEPRECATION")
|
|
||||||
|
|
||||||
package com.topjohnwu.magisk.core.utils.net
|
package com.topjohnwu.magisk.core.utils.net
|
||||||
|
|
||||||
import android.annotation.TargetApi
|
import android.annotation.TargetApi
|
||||||
@ -32,7 +30,7 @@ class MarshmallowNetworkObserver(
|
|||||||
|
|
||||||
override fun getCurrentState() {
|
override fun getCurrentState() {
|
||||||
callback(manager.getNetworkCapabilities(manager.activeNetwork)
|
callback(manager.getNetworkCapabilities(manager.activeNetwork)
|
||||||
?.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) ?: false)
|
?.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED) ?: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class IdleBroadcastReceiver: BroadcastReceiver() {
|
private inner class IdleBroadcastReceiver: BroadcastReceiver() {
|
||||||
|
Loading…
Reference in New Issue
Block a user