Deprecate usage of BuildCompat
This commit is contained in:
10
README.md
10
README.md
@@ -160,11 +160,11 @@ Hidden whitelisted APIs: (same catch as above, however, things in this list are
|
|||||||
|
|
||||||
* (since API 24) `Landroid/bluetooth/BluetoothPan;->isTetheringOn()Z,system-api,whitelist`
|
* (since API 24) `Landroid/bluetooth/BluetoothPan;->isTetheringOn()Z,system-api,whitelist`
|
||||||
* (since API 30) `Landroid/content/Context;->TETHERING_SERVICE:Ljava/lang/String;,system-api,whitelist`
|
* (since API 30) `Landroid/content/Context;->TETHERING_SERVICE:Ljava/lang/String;,system-api,whitelist`
|
||||||
* (since API 24) [`Landroid/net/ConnectivityManager$OnStartTetheringCallback;-><init>()V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#123103)
|
* (since API 24, prior to API 30) [`Landroid/net/ConnectivityManager$OnStartTetheringCallback;-><init>()V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#123103)
|
||||||
* (since API 24) [`Landroid/net/ConnectivityManager$OnStartTetheringCallback;->onTetheringFailed()V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#123104)
|
* (since API 24, prior to API 30) [`Landroid/net/ConnectivityManager$OnStartTetheringCallback;->onTetheringFailed()V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#123104)
|
||||||
* (since API 24) [`Landroid/net/ConnectivityManager$OnStartTetheringCallback;->onTetheringStarted()V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#123105)
|
* (since API 24, prior to API 30) [`Landroid/net/ConnectivityManager$OnStartTetheringCallback;->onTetheringStarted()V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#123105)
|
||||||
* (since API 24) [`Landroid/net/ConnectivityManager;->startTethering(IZLandroid/net/ConnectivityManager$OnStartTetheringCallback;Landroid/os/Handler;)V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#123408)
|
* (since API 24, prior to API 30) [`Landroid/net/ConnectivityManager;->startTethering(IZLandroid/net/ConnectivityManager$OnStartTetheringCallback;Landroid/os/Handler;)V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#123408)
|
||||||
* (since API 24) [`Landroid/net/ConnectivityManager;->stopTethering(I)V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#123410)
|
* (since API 24, prior to API 30) [`Landroid/net/ConnectivityManager;->stopTethering(I)V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#123410)
|
||||||
* (since API 30) `Landroid/net/TetheringManager$StartTetheringCallback;->onTetheringFailed(I)V,system-api,test-api,whitelist`
|
* (since API 30) `Landroid/net/TetheringManager$StartTetheringCallback;->onTetheringFailed(I)V,system-api,test-api,whitelist`
|
||||||
* (since API 30) `Landroid/net/TetheringManager$StartTetheringCallback;->onTetheringStarted()V,system-api,test-api,whitelist`
|
* (since API 30) `Landroid/net/TetheringManager$StartTetheringCallback;->onTetheringStarted()V,system-api,test-api,whitelist`
|
||||||
* (since API 30) `Landroid/net/TetheringManager$TetheringEventCallback;->onClientsChanged(Ljava/util/Collection;)V,system-api,test-api,whitelist`
|
* (since API 30) `Landroid/net/TetheringManager$TetheringEventCallback;->onClientsChanged(Ljava/util/Collection;)V,system-api,test-api,whitelist`
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import android.content.IntentFilter
|
|||||||
import android.net.wifi.WifiManager
|
import android.net.wifi.WifiManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.core.os.BuildCompat
|
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.net.IpNeighbour
|
import be.mygod.vpnhotspot.net.IpNeighbour
|
||||||
import be.mygod.vpnhotspot.net.TetheringManager
|
import be.mygod.vpnhotspot.net.TetheringManager
|
||||||
@@ -33,11 +32,9 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService(), CoroutineScope {
|
|||||||
}
|
}
|
||||||
val ifaceChanged = StickyEvent1 { iface }
|
val ifaceChanged = StickyEvent1 { iface }
|
||||||
|
|
||||||
val configuration get() = if (BuildCompat.isAtLeastR()) {
|
val configuration get() = if (Build.VERSION.SDK_INT < 30) @Suppress("DEPRECATION") {
|
||||||
reservation?.softApConfiguration?.toCompat()
|
|
||||||
} else @Suppress("DEPRECATION") {
|
|
||||||
reservation?.wifiConfiguration?.toCompat()
|
reservation?.wifiConfiguration?.toCompat()
|
||||||
}
|
} else reservation?.softApConfiguration?.toCompat()
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
when (iface) {
|
when (iface) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package be.mygod.vpnhotspot
|
|||||||
|
|
||||||
import android.annotation.TargetApi
|
import android.annotation.TargetApi
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.core.os.BuildCompat
|
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.net.Routing
|
import be.mygod.vpnhotspot.net.Routing
|
||||||
import be.mygod.vpnhotspot.net.TetherType
|
import be.mygod.vpnhotspot.net.TetherType
|
||||||
@@ -61,7 +60,7 @@ abstract class RoutingManager(private val caller: Any, val downstream: String, p
|
|||||||
fun start() = when (val other = active.putIfAbsent(downstream, this)) {
|
fun start() = when (val other = active.putIfAbsent(downstream, this)) {
|
||||||
null -> {
|
null -> {
|
||||||
if (isWifi) WifiDoubleLock.acquire(this)
|
if (isWifi) WifiDoubleLock.acquire(this)
|
||||||
if (!forceWifi && BuildCompat.isAtLeastR()) TetherType.listener[this] = {
|
if (!forceWifi && Build.VERSION.SDK_INT >= 30) TetherType.listener[this] = {
|
||||||
val isWifiNow = TetherType.ofInterface(downstream).isWifi
|
val isWifiNow = TetherType.ofInterface(downstream).isWifi
|
||||||
if (isWifi != isWifiNow) {
|
if (isWifi != isWifiNow) {
|
||||||
if (isWifi) WifiDoubleLock.release(this) else WifiDoubleLock.acquire(this)
|
if (isWifi) WifiDoubleLock.release(this) else WifiDoubleLock.acquire(this)
|
||||||
@@ -97,7 +96,7 @@ abstract class RoutingManager(private val caller: Any, val downstream: String, p
|
|||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
if (active.remove(downstream, this)) {
|
if (active.remove(downstream, this)) {
|
||||||
if (!forceWifi && BuildCompat.isAtLeastR()) TetherType.listener -= this
|
if (!forceWifi && Build.VERSION.SDK_INT >= 30) TetherType.listener -= this
|
||||||
if (isWifi) WifiDoubleLock.release(this)
|
if (isWifi) WifiDoubleLock.release(this)
|
||||||
routing?.revert()
|
routing?.revert()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package be.mygod.vpnhotspot.client
|
package be.mygod.vpnhotspot.client
|
||||||
|
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.text.format.DateUtils
|
import android.text.format.DateUtils
|
||||||
@@ -14,7 +15,6 @@ import android.view.ViewGroup
|
|||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.widget.PopupMenu
|
import androidx.appcompat.widget.PopupMenu
|
||||||
import androidx.core.os.BuildCompat
|
|
||||||
import androidx.databinding.BaseObservable
|
import androidx.databinding.BaseObservable
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
@@ -235,7 +235,7 @@ class ClientsFragment : Fragment() {
|
|||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
// icon might be changed due to TetherType changes
|
// icon might be changed due to TetherType changes
|
||||||
if (BuildCompat.isAtLeastR()) TetherType.listener[this] = {
|
if (Build.VERSION.SDK_INT >= 30) TetherType.listener[this] = {
|
||||||
lifecycleScope.launchWhenStarted { adapter.notifyItemRangeChanged(0, adapter.size.await()) }
|
lifecycleScope.launchWhenStarted { adapter.notifyItemRangeChanged(0, adapter.size.await()) }
|
||||||
}
|
}
|
||||||
super.onStart()
|
super.onStart()
|
||||||
@@ -251,6 +251,6 @@ class ClientsFragment : Fragment() {
|
|||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
TrafficRecorder.foregroundListeners -= this
|
TrafficRecorder.foregroundListeners -= this
|
||||||
super.onStop()
|
super.onStop()
|
||||||
if (BuildCompat.isAtLeastR()) TetherType.listener -= this
|
if (Build.VERSION.SDK_INT >= 30) TetherType.listener -= this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import android.content.BroadcastReceiver
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
|
import android.os.Build
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.core.os.BuildCompat
|
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.net.TetheringManager
|
import be.mygod.vpnhotspot.net.TetheringManager
|
||||||
import be.mygod.vpnhotspot.util.broadcastReceiver
|
import be.mygod.vpnhotspot.util.broadcastReceiver
|
||||||
@@ -95,7 +95,7 @@ class BluetoothTethering(context: Context, val stateListener: (Int) -> Unit) :
|
|||||||
isTetheringOn(pan) as Boolean
|
isTetheringOn(pan) as Boolean
|
||||||
} catch (e: InvocationTargetException) {
|
} catch (e: InvocationTargetException) {
|
||||||
activeFailureCause = e.cause ?: e
|
activeFailureCause = e.cause ?: e
|
||||||
if (e.cause is SecurityException && BuildCompat.isAtLeastR()) Timber.d(e) else Timber.w(e)
|
if (e.cause is SecurityException && Build.VERSION.SDK_INT >= 30) Timber.d(e) else Timber.w(e)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import androidx.activity.result.contract.ActivityResultContracts
|
|||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.os.BuildCompat
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.DefaultItemAnimator
|
import androidx.recyclerview.widget.DefaultItemAnimator
|
||||||
@@ -101,7 +100,7 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
|
|||||||
list.addAll(tetherManagers)
|
list.addAll(tetherManagers)
|
||||||
tetherManagers.forEach { it.updateErrorMessage(erroredIfaces) }
|
tetherManagers.forEach { it.updateErrorMessage(erroredIfaces) }
|
||||||
}
|
}
|
||||||
if (BuildCompat.isAtLeastR()) {
|
if (Build.VERSION.SDK_INT >= 30) {
|
||||||
list.addAll(tetherManagers30)
|
list.addAll(tetherManagers30)
|
||||||
tetherManagers30.forEach { it.updateErrorMessage(erroredIfaces) }
|
tetherManagers30.forEach { it.updateErrorMessage(erroredIfaces) }
|
||||||
}
|
}
|
||||||
@@ -229,7 +228,7 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
|
|||||||
lifecycleScope.launchWhenStarted { adapter.notifyInterfaceChanged() }
|
lifecycleScope.launchWhenStarted { adapter.notifyInterfaceChanged() }
|
||||||
}
|
}
|
||||||
requireContext().registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED))
|
requireContext().registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED))
|
||||||
if (BuildCompat.isAtLeastR()) TetherType.listener[this] = {
|
if (Build.VERSION.SDK_INT >= 30) TetherType.listener[this] = {
|
||||||
lifecycleScope.launchWhenStarted { adapter.notifyTetherTypeChanged() }
|
lifecycleScope.launchWhenStarted { adapter.notifyTetherTypeChanged() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,7 +236,7 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
|
|||||||
override fun onServiceDisconnected(name: ComponentName?) {
|
override fun onServiceDisconnected(name: ComponentName?) {
|
||||||
(binder ?: return).routingsChanged -= this
|
(binder ?: return).routingsChanged -= this
|
||||||
binder = null
|
binder = null
|
||||||
if (BuildCompat.isAtLeastR()) TetherType.listener -= this
|
if (Build.VERSION.SDK_INT >= 30) TetherType.listener -= this
|
||||||
requireContext().unregisterReceiver(receiver)
|
requireContext().unregisterReceiver(receiver)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
import android.graphics.drawable.Icon
|
import android.graphics.drawable.Icon
|
||||||
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.service.quicksettings.Tile
|
import android.service.quicksettings.Tile
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.os.BuildCompat
|
|
||||||
import be.mygod.vpnhotspot.R
|
import be.mygod.vpnhotspot.R
|
||||||
import be.mygod.vpnhotspot.TetheringService
|
import be.mygod.vpnhotspot.TetheringService
|
||||||
import be.mygod.vpnhotspot.net.TetherType
|
import be.mygod.vpnhotspot.net.TetherType
|
||||||
@@ -51,12 +51,12 @@ sealed class TetheringTileService : KillableTileService(), TetheringManager.Star
|
|||||||
// we need to initialize tethered ASAP for onClick, which is not achievable using registerTetheringEventCallback
|
// we need to initialize tethered ASAP for onClick, which is not achievable using registerTetheringEventCallback
|
||||||
tethered = registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED))
|
tethered = registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED))
|
||||||
?.tetheredIfaces
|
?.tetheredIfaces
|
||||||
if (BuildCompat.isAtLeastR()) TetherType.listener[this] = this::updateTile
|
if (Build.VERSION.SDK_INT >= 30) TetherType.listener[this] = this::updateTile
|
||||||
updateTile()
|
updateTile()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStopListening() {
|
override fun onStopListening() {
|
||||||
if (BuildCompat.isAtLeastR()) TetherType.listener -= this
|
if (Build.VERSION.SDK_INT >= 30) TetherType.listener -= this
|
||||||
unregisterReceiver(receiver)
|
unregisterReceiver(receiver)
|
||||||
stopAndUnbind(this)
|
stopAndUnbind(this)
|
||||||
super.onStopListening()
|
super.onStopListening()
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package be.mygod.vpnhotspot.net
|
package be.mygod.vpnhotspot.net
|
||||||
|
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
|
import android.os.Build
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.core.os.BuildCompat
|
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.R
|
import be.mygod.vpnhotspot.R
|
||||||
import be.mygod.vpnhotspot.util.Event0
|
import be.mygod.vpnhotspot.util.Event0
|
||||||
@@ -71,7 +71,7 @@ enum class TetherType(@DrawableRes val icon: Int) {
|
|||||||
*/
|
*/
|
||||||
init {
|
init {
|
||||||
val system = "android" to Resources.getSystem()
|
val system = "android" to Resources.getSystem()
|
||||||
if (BuildCompat.isAtLeastR()) requiresUpdate = true else {
|
if (Build.VERSION.SDK_INT >= 30) requiresUpdate = true else {
|
||||||
usbRegexs = system.getRegexs("config_tether_usb_regexs")
|
usbRegexs = system.getRegexs("config_tether_usb_regexs")
|
||||||
wifiRegexs = system.getRegexs("config_tether_wifi_regexs")
|
wifiRegexs = system.getRegexs("config_tether_wifi_regexs")
|
||||||
bluetoothRegexs = system.getRegexs("config_tether_bluetooth_regexs")
|
bluetoothRegexs = system.getRegexs("config_tether_bluetooth_regexs")
|
||||||
@@ -92,7 +92,7 @@ enum class TetherType(@DrawableRes val icon: Int) {
|
|||||||
iface == null -> NONE
|
iface == null -> NONE
|
||||||
iface == p2pDev -> WIFI_P2P
|
iface == p2pDev -> WIFI_P2P
|
||||||
requiresUpdate -> {
|
requiresUpdate -> {
|
||||||
if (BuildCompat.isAtLeastR()) updateRegexs() else error("unexpected requiresUpdate")
|
if (Build.VERSION.SDK_INT >= 30) updateRegexs() else error("unexpected requiresUpdate")
|
||||||
ofInterface(iface, p2pDev)
|
ofInterface(iface, p2pDev)
|
||||||
}
|
}
|
||||||
wifiRegexs.any { it.matcher(iface).matches() } -> WIFI
|
wifiRegexs.any { it.matcher(iface).matches() } -> WIFI
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import android.os.Build
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.collection.SparseArrayCompat
|
import androidx.collection.SparseArrayCompat
|
||||||
import androidx.core.os.BuildCompat
|
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.R
|
import be.mygod.vpnhotspot.R
|
||||||
import be.mygod.vpnhotspot.util.broadcastReceiver
|
import be.mygod.vpnhotspot.util.broadcastReceiver
|
||||||
@@ -237,7 +236,7 @@ object TetheringManager {
|
|||||||
fun startTethering(type: Int, showProvisioningUi: Boolean, callback: StartTetheringCallback,
|
fun startTethering(type: Int, showProvisioningUi: Boolean, callback: StartTetheringCallback,
|
||||||
handler: Handler? = null) {
|
handler: Handler? = null) {
|
||||||
val reference = WeakReference(callback)
|
val reference = WeakReference(callback)
|
||||||
if (BuildCompat.isAtLeastR()) try {
|
if (Build.VERSION.SDK_INT >= 30) {
|
||||||
val request = newTetheringRequestBuilder.newInstance(type).let { builder ->
|
val request = newTetheringRequestBuilder.newInstance(type).let { builder ->
|
||||||
// setting exemption requires TETHER_PRIVILEGED permission
|
// setting exemption requires TETHER_PRIVILEGED permission
|
||||||
if (app.checkSelfPermission("android.permission.TETHER_PRIVILEGED") ==
|
if (app.checkSelfPermission("android.permission.TETHER_PRIVILEGED") ==
|
||||||
@@ -263,23 +262,21 @@ object TetheringManager {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
startTethering(instance, request, handler.makeExecutor(), proxy)
|
startTethering(instance, request, handler.makeExecutor(), proxy)
|
||||||
return
|
} else {
|
||||||
} catch (e: InvocationTargetException) {
|
val proxy = ProxyBuilder.forClass(classOnStartTetheringCallback).apply {
|
||||||
Timber.w(e, "Unable to invoke TetheringManager.startTethering, falling back to ConnectivityManager")
|
dexCache(app.deviceStorage.cacheDir)
|
||||||
}
|
handler { proxy, method, args ->
|
||||||
val proxy = ProxyBuilder.forClass(classOnStartTetheringCallback).apply {
|
if (args.isNotEmpty()) Timber.w("Unexpected args for ${method.name}: $args")
|
||||||
dexCache(app.deviceStorage.cacheDir)
|
@Suppress("NAME_SHADOWING") val callback = reference.get()
|
||||||
handler { proxy, method, args ->
|
when (method.name) {
|
||||||
if (args.isNotEmpty()) Timber.w("Unexpected args for ${method.name}: $args")
|
"onTetheringStarted" -> callback?.onTetheringStarted()
|
||||||
@Suppress("NAME_SHADOWING") val callback = reference.get()
|
"onTetheringFailed" -> callback?.onTetheringFailed()
|
||||||
when (method.name) {
|
else -> ProxyBuilder.callSuper(proxy, method, args)
|
||||||
"onTetheringStarted" -> callback?.onTetheringStarted()
|
}
|
||||||
"onTetheringFailed" -> callback?.onTetheringFailed()
|
|
||||||
else -> ProxyBuilder.callSuper(proxy, method, args)
|
|
||||||
}
|
}
|
||||||
}
|
}.build()
|
||||||
}.build()
|
startTetheringLegacy(app.connectivity, type, showProvisioningUi, proxy, handler)
|
||||||
startTetheringLegacy(app.connectivity, type, showProvisioningUi, proxy, handler)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -293,12 +290,7 @@ object TetheringManager {
|
|||||||
*/
|
*/
|
||||||
@RequiresApi(24)
|
@RequiresApi(24)
|
||||||
fun stopTethering(type: Int) {
|
fun stopTethering(type: Int) {
|
||||||
if (BuildCompat.isAtLeastR()) try {
|
if (Build.VERSION.SDK_INT >= 30) stopTethering(instance, type) else stopTetheringLegacy(app.connectivity, type)
|
||||||
stopTethering(instance, type)
|
|
||||||
} catch (e: InvocationTargetException) {
|
|
||||||
Timber.w(e, "Unable to invoke TetheringManager.stopTethering, falling back to ConnectivityManager")
|
|
||||||
}
|
|
||||||
stopTetheringLegacy(app.connectivity, type)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -498,7 +490,7 @@ object TetheringManager {
|
|||||||
* Only [TetheringEventCallback.onTetheredInterfacesChanged] is supported on API 29-.
|
* Only [TetheringEventCallback.onTetheredInterfacesChanged] is supported on API 29-.
|
||||||
*/
|
*/
|
||||||
fun registerTetheringEventCallbackCompat(context: Context, callback: TetheringEventCallback) {
|
fun registerTetheringEventCallbackCompat(context: Context, callback: TetheringEventCallback) {
|
||||||
if (BuildCompat.isAtLeastR()) {
|
if (Build.VERSION.SDK_INT >= 30) {
|
||||||
registerTetheringEventCallback(null.makeExecutor(), callback)
|
registerTetheringEventCallback(null.makeExecutor(), callback)
|
||||||
} else synchronized(callbackMap) {
|
} else synchronized(callbackMap) {
|
||||||
callbackMap.computeIfAbsent(callback) {
|
callbackMap.computeIfAbsent(callback) {
|
||||||
@@ -509,7 +501,7 @@ object TetheringManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun unregisterTetheringEventCallbackCompat(context: Context, callback: TetheringEventCallback) {
|
fun unregisterTetheringEventCallbackCompat(context: Context, callback: TetheringEventCallback) {
|
||||||
if (BuildCompat.isAtLeastR()) {
|
if (Build.VERSION.SDK_INT >= 30) {
|
||||||
unregisterTetheringEventCallback(callback)
|
unregisterTetheringEventCallback(callback)
|
||||||
} else {
|
} else {
|
||||||
val receiver = synchronized(callbackMap) { callbackMap.remove(callback) } ?: return
|
val receiver = synchronized(callbackMap) { callbackMap.remove(callback) } ?: return
|
||||||
@@ -545,7 +537,7 @@ object TetheringManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun tetherErrorMessage(error: Int): String {
|
fun tetherErrorMessage(error: Int): String {
|
||||||
if (BuildCompat.isAtLeastR()) try {
|
if (Build.VERSION.SDK_INT >= 30) try {
|
||||||
tetherErrors.get(error)?.let { return it }
|
tetherErrors.get(error)?.let { return it }
|
||||||
} catch (e: ReflectiveOperationException) {
|
} catch (e: ReflectiveOperationException) {
|
||||||
Timber.w(e)
|
Timber.w(e)
|
||||||
@@ -557,6 +549,6 @@ object TetheringManager {
|
|||||||
if (Build.VERSION.SDK_INT >= 26) EXTRA_ACTIVE_TETHER else EXTRA_ACTIVE_TETHER_LEGACY)
|
if (Build.VERSION.SDK_INT >= 26) EXTRA_ACTIVE_TETHER else EXTRA_ACTIVE_TETHER_LEGACY)
|
||||||
val Intent.localOnlyTetheredIfaces get() = if (Build.VERSION.SDK_INT >= 26) {
|
val Intent.localOnlyTetheredIfaces get() = if (Build.VERSION.SDK_INT >= 26) {
|
||||||
getStringArrayListExtra(
|
getStringArrayListExtra(
|
||||||
if (BuildCompat.isAtLeastR()) EXTRA_ACTIVE_LOCAL_ONLY else EXTRA_ACTIVE_LOCAL_ONLY_LEGACY)
|
if (Build.VERSION.SDK_INT >= 30) EXTRA_ACTIVE_LOCAL_ONLY else EXTRA_ACTIVE_LOCAL_ONLY_LEGACY)
|
||||||
} else emptyList<String>()
|
} else emptyList<String>()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package be.mygod.vpnhotspot.net.monitor
|
package be.mygod.vpnhotspot.net.monitor
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
import android.system.ErrnoException
|
import android.system.ErrnoException
|
||||||
import android.system.OsConstants
|
import android.system.OsConstants
|
||||||
import androidx.core.os.BuildCompat
|
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.R
|
import be.mygod.vpnhotspot.R
|
||||||
import be.mygod.vpnhotspot.util.RootSession
|
import be.mygod.vpnhotspot.util.RootSession
|
||||||
@@ -21,8 +21,12 @@ abstract class IpMonitor : Runnable {
|
|||||||
// https://android.googlesource.com/platform/external/iproute2/+/7f7a711/lib/libnetlink.c#493
|
// https://android.googlesource.com/platform/external/iproute2/+/7f7a711/lib/libnetlink.c#493
|
||||||
private val errorMatcher = "(^Cannot bind netlink socket: |Dump (was interrupted and may be inconsistent.|terminated)$)"
|
private val errorMatcher = "(^Cannot bind netlink socket: |Dump (was interrupted and may be inconsistent.|terminated)$)"
|
||||||
.toRegex()
|
.toRegex()
|
||||||
private val currentMode get() = Mode.valueOf(app.pref.getString(KEY, (if (BuildCompat.isAtLeastR())
|
private val currentMode: Mode get() {
|
||||||
Mode.MonitorRoot else @Suppress("DEPRECATION") Mode.Poll).toString()) ?: "")
|
val defaultMode = if (Build.VERSION.SDK_INT < 30) @Suppress("DEPRECATION") {
|
||||||
|
Mode.Poll
|
||||||
|
} else Mode.MonitorRoot
|
||||||
|
return Mode.valueOf(app.pref.getString(KEY, defaultMode.toString()) ?: "")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class Mode(val isMonitor: Boolean = false) {
|
enum class Mode(val isMonitor: Boolean = false) {
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import android.widget.ArrayAdapter
|
|||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.core.os.BuildCompat
|
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import be.mygod.vpnhotspot.AlertDialogFragment
|
import be.mygod.vpnhotspot.AlertDialogFragment
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
@@ -128,7 +127,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
|
|||||||
if (Build.VERSION.SDK_INT >= 28) add(BandOption.BandAny)
|
if (Build.VERSION.SDK_INT >= 28) add(BandOption.BandAny)
|
||||||
add(BandOption.Band2GHz)
|
add(BandOption.Band2GHz)
|
||||||
add(BandOption.Band5GHz)
|
add(BandOption.Band5GHz)
|
||||||
if (BuildCompat.isAtLeastR()) add(BandOption.Band6GHz)
|
if (Build.VERSION.SDK_INT >= 30) add(BandOption.Band6GHz)
|
||||||
}
|
}
|
||||||
addAll(channels)
|
addAll(channels)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package be.mygod.vpnhotspot.net.wifi
|
|||||||
import android.annotation.TargetApi
|
import android.annotation.TargetApi
|
||||||
import android.net.wifi.SoftApConfiguration
|
import android.net.wifi.SoftApConfiguration
|
||||||
import android.net.wifi.WifiManager
|
import android.net.wifi.WifiManager
|
||||||
|
import android.os.Build
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.core.os.BuildCompat
|
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.net.wifi.SoftApConfigurationCompat.Companion.toCompat
|
import be.mygod.vpnhotspot.net.wifi.SoftApConfigurationCompat.Companion.toCompat
|
||||||
|
|
||||||
@@ -23,17 +23,15 @@ object WifiApManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var configuration: SoftApConfigurationCompat
|
var configuration: SoftApConfigurationCompat
|
||||||
get() = if (BuildCompat.isAtLeastR()) {
|
get() = if (Build.VERSION.SDK_INT < 30) @Suppress("DEPRECATION") {
|
||||||
(getSoftApConfiguration(app.wifi) as SoftApConfiguration).toCompat()
|
|
||||||
} else @Suppress("DEPRECATION") {
|
|
||||||
(getWifiApConfiguration(app.wifi) as android.net.wifi.WifiConfiguration?)?.toCompat()
|
(getWifiApConfiguration(app.wifi) as android.net.wifi.WifiConfiguration?)?.toCompat()
|
||||||
?: SoftApConfigurationCompat.empty()
|
?: SoftApConfigurationCompat.empty()
|
||||||
}
|
} else (getSoftApConfiguration(app.wifi) as SoftApConfiguration).toCompat()
|
||||||
set(value) = if (BuildCompat.isAtLeastR()) {
|
set(value) = if (Build.VERSION.SDK_INT < 30) @Suppress("DEPRECATION") {
|
||||||
require(setSoftApConfiguration(app.wifi, value.toPlatform()) as Boolean) { "setSoftApConfiguration failed" }
|
|
||||||
} else @Suppress("DEPRECATION") {
|
|
||||||
require(setWifiApConfiguration(app.wifi,
|
require(setWifiApConfiguration(app.wifi,
|
||||||
value.toWifiConfiguration()) as Boolean) { "setWifiApConfiguration failed" }
|
value.toWifiConfiguration()) as Boolean) { "setWifiApConfiguration failed" }
|
||||||
|
} else require(setSoftApConfiguration(app.wifi, value.toPlatform()) as Boolean) {
|
||||||
|
"setSoftApConfiguration failed"
|
||||||
}
|
}
|
||||||
|
|
||||||
private val cancelLocalOnlyHotspotRequest by lazy {
|
private val cancelLocalOnlyHotspotRequest by lazy {
|
||||||
|
|||||||
Reference in New Issue
Block a user