From b9994bda9e8db9c24abcd9c23cb2ac7d13bfee75 Mon Sep 17 00:00:00 2001 From: Mygod Date: Thu, 11 Jun 2020 03:17:42 +0800 Subject: [PATCH] Deprecate usage of BuildCompat --- README.md | 10 ++-- .../vpnhotspot/LocalOnlyHotspotService.kt | 7 +-- .../be/mygod/vpnhotspot/RoutingManager.kt | 5 +- .../vpnhotspot/client/ClientsFragment.kt | 6 +-- .../vpnhotspot/manage/BluetoothTethering.kt | 4 +- .../vpnhotspot/manage/TetheringFragment.kt | 7 ++- .../vpnhotspot/manage/TetheringTileService.kt | 6 +-- .../be/mygod/vpnhotspot/net/TetherType.kt | 6 +-- .../mygod/vpnhotspot/net/TetheringManager.kt | 48 ++++++++----------- .../mygod/vpnhotspot/net/monitor/IpMonitor.kt | 10 ++-- .../net/wifi/WifiApDialogFragment.kt | 3 +- .../vpnhotspot/net/wifi/WifiApManager.kt | 14 +++--- 12 files changed, 57 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 537b4da2..c06a7678 100644 --- a/README.md +++ b/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 30) `Landroid/content/Context;->TETHERING_SERVICE:Ljava/lang/String;,system-api,whitelist` -* (since API 24) [`Landroid/net/ConnectivityManager$OnStartTetheringCallback;->()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) [`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) [`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$OnStartTetheringCallback;->()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;->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;->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;->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;->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;->onTetheringStarted()V,system-api,test-api,whitelist` * (since API 30) `Landroid/net/TetheringManager$TetheringEventCallback;->onClientsChanged(Ljava/util/Collection;)V,system-api,test-api,whitelist` diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt index ccbc785c..22ad60f0 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt @@ -5,7 +5,6 @@ import android.content.IntentFilter import android.net.wifi.WifiManager import android.os.Build import androidx.annotation.RequiresApi -import androidx.core.os.BuildCompat import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.net.IpNeighbour import be.mygod.vpnhotspot.net.TetheringManager @@ -33,11 +32,9 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService(), CoroutineScope { } val ifaceChanged = StickyEvent1 { iface } - val configuration get() = if (BuildCompat.isAtLeastR()) { - reservation?.softApConfiguration?.toCompat() - } else @Suppress("DEPRECATION") { + val configuration get() = if (Build.VERSION.SDK_INT < 30) @Suppress("DEPRECATION") { reservation?.wifiConfiguration?.toCompat() - } + } else reservation?.softApConfiguration?.toCompat() fun stop() { when (iface) { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/RoutingManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/RoutingManager.kt index d0919620..9a7ca3f7 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/RoutingManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/RoutingManager.kt @@ -2,7 +2,6 @@ package be.mygod.vpnhotspot import android.annotation.TargetApi import android.os.Build -import androidx.core.os.BuildCompat import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.net.Routing 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)) { null -> { 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 if (isWifi != isWifiNow) { 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() { 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) routing?.revert() } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt index a9b29746..87343cd2 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt @@ -1,6 +1,7 @@ package be.mygod.vpnhotspot.client import android.content.DialogInterface +import android.os.Build import android.os.Bundle import android.os.Parcelable import android.text.format.DateUtils @@ -14,7 +15,6 @@ import android.view.ViewGroup import android.widget.EditText import androidx.appcompat.app.AlertDialog import androidx.appcompat.widget.PopupMenu -import androidx.core.os.BuildCompat import androidx.databinding.BaseObservable import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels @@ -235,7 +235,7 @@ class ClientsFragment : Fragment() { override fun onStart() { // 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()) } } super.onStart() @@ -251,6 +251,6 @@ class ClientsFragment : Fragment() { override fun onStop() { TrafficRecorder.foregroundListeners -= this super.onStop() - if (BuildCompat.isAtLeastR()) TetherType.listener -= this + if (Build.VERSION.SDK_INT >= 30) TetherType.listener -= this } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/BluetoothTethering.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/BluetoothTethering.kt index 8722c23c..9f1e3c51 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/BluetoothTethering.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/BluetoothTethering.kt @@ -7,9 +7,9 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter +import android.os.Build import android.widget.Toast import androidx.annotation.RequiresApi -import androidx.core.os.BuildCompat import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.net.TetheringManager import be.mygod.vpnhotspot.util.broadcastReceiver @@ -95,7 +95,7 @@ class BluetoothTethering(context: Context, val stateListener: (Int) -> Unit) : isTetheringOn(pan) as Boolean } catch (e: InvocationTargetException) { 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 } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt index a7d7e062..f42baa76 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt @@ -13,7 +13,6 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.annotation.RequiresApi import androidx.appcompat.widget.Toolbar import androidx.core.content.ContextCompat -import androidx.core.os.BuildCompat import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.DefaultItemAnimator @@ -101,7 +100,7 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick list.addAll(tetherManagers) tetherManagers.forEach { it.updateErrorMessage(erroredIfaces) } } - if (BuildCompat.isAtLeastR()) { + if (Build.VERSION.SDK_INT >= 30) { list.addAll(tetherManagers30) tetherManagers30.forEach { it.updateErrorMessage(erroredIfaces) } } @@ -229,7 +228,7 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick lifecycleScope.launchWhenStarted { adapter.notifyInterfaceChanged() } } 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() } } } @@ -237,7 +236,7 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick override fun onServiceDisconnected(name: ComponentName?) { (binder ?: return).routingsChanged -= this binder = null - if (BuildCompat.isAtLeastR()) TetherType.listener -= this + if (Build.VERSION.SDK_INT >= 30) TetherType.listener -= this requireContext().unregisterReceiver(receiver) } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringTileService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringTileService.kt index ce377e3f..469eb63c 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringTileService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringTileService.kt @@ -5,12 +5,12 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.graphics.drawable.Icon +import android.os.Build import android.os.IBinder import android.service.quicksettings.Tile import android.widget.Toast import androidx.annotation.RequiresApi import androidx.core.content.ContextCompat -import androidx.core.os.BuildCompat import be.mygod.vpnhotspot.R import be.mygod.vpnhotspot.TetheringService 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 tethered = registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED)) ?.tetheredIfaces - if (BuildCompat.isAtLeastR()) TetherType.listener[this] = this::updateTile + if (Build.VERSION.SDK_INT >= 30) TetherType.listener[this] = this::updateTile updateTile() } override fun onStopListening() { - if (BuildCompat.isAtLeastR()) TetherType.listener -= this + if (Build.VERSION.SDK_INT >= 30) TetherType.listener -= this unregisterReceiver(receiver) stopAndUnbind(this) super.onStopListening() diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetherType.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetherType.kt index 53e670d3..6ea49aac 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetherType.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetherType.kt @@ -1,9 +1,9 @@ package be.mygod.vpnhotspot.net import android.content.res.Resources +import android.os.Build import androidx.annotation.DrawableRes import androidx.annotation.RequiresApi -import androidx.core.os.BuildCompat import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.R import be.mygod.vpnhotspot.util.Event0 @@ -71,7 +71,7 @@ enum class TetherType(@DrawableRes val icon: Int) { */ init { 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") wifiRegexs = system.getRegexs("config_tether_wifi_regexs") bluetoothRegexs = system.getRegexs("config_tether_bluetooth_regexs") @@ -92,7 +92,7 @@ enum class TetherType(@DrawableRes val icon: Int) { iface == null -> NONE iface == p2pDev -> WIFI_P2P requiresUpdate -> { - if (BuildCompat.isAtLeastR()) updateRegexs() else error("unexpected requiresUpdate") + if (Build.VERSION.SDK_INT >= 30) updateRegexs() else error("unexpected requiresUpdate") ofInterface(iface, p2pDev) } wifiRegexs.any { it.matcher(iface).matches() } -> WIFI diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt index 34f16a84..8443e40e 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt @@ -13,7 +13,6 @@ import android.os.Build import android.os.Handler import androidx.annotation.RequiresApi import androidx.collection.SparseArrayCompat -import androidx.core.os.BuildCompat import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.R import be.mygod.vpnhotspot.util.broadcastReceiver @@ -237,7 +236,7 @@ object TetheringManager { fun startTethering(type: Int, showProvisioningUi: Boolean, callback: StartTetheringCallback, handler: Handler? = null) { val reference = WeakReference(callback) - if (BuildCompat.isAtLeastR()) try { + if (Build.VERSION.SDK_INT >= 30) { val request = newTetheringRequestBuilder.newInstance(type).let { builder -> // setting exemption requires TETHER_PRIVILEGED permission if (app.checkSelfPermission("android.permission.TETHER_PRIVILEGED") == @@ -263,23 +262,21 @@ object TetheringManager { } }) startTethering(instance, request, handler.makeExecutor(), proxy) - return - } catch (e: InvocationTargetException) { - Timber.w(e, "Unable to invoke TetheringManager.startTethering, falling back to ConnectivityManager") - } - val proxy = ProxyBuilder.forClass(classOnStartTetheringCallback).apply { - dexCache(app.deviceStorage.cacheDir) - handler { proxy, method, args -> - if (args.isNotEmpty()) Timber.w("Unexpected args for ${method.name}: $args") - @Suppress("NAME_SHADOWING") val callback = reference.get() - when (method.name) { - "onTetheringStarted" -> callback?.onTetheringStarted() - "onTetheringFailed" -> callback?.onTetheringFailed() - else -> ProxyBuilder.callSuper(proxy, method, args) + } else { + val proxy = ProxyBuilder.forClass(classOnStartTetheringCallback).apply { + dexCache(app.deviceStorage.cacheDir) + handler { proxy, method, args -> + if (args.isNotEmpty()) Timber.w("Unexpected args for ${method.name}: $args") + @Suppress("NAME_SHADOWING") val callback = reference.get() + when (method.name) { + "onTetheringStarted" -> callback?.onTetheringStarted() + "onTetheringFailed" -> callback?.onTetheringFailed() + else -> ProxyBuilder.callSuper(proxy, method, args) + } } - } - }.build() - startTetheringLegacy(app.connectivity, type, showProvisioningUi, proxy, handler) + }.build() + startTetheringLegacy(app.connectivity, type, showProvisioningUi, proxy, handler) + } } /** @@ -293,12 +290,7 @@ object TetheringManager { */ @RequiresApi(24) fun stopTethering(type: Int) { - if (BuildCompat.isAtLeastR()) try { - stopTethering(instance, type) - } catch (e: InvocationTargetException) { - Timber.w(e, "Unable to invoke TetheringManager.stopTethering, falling back to ConnectivityManager") - } - stopTetheringLegacy(app.connectivity, type) + if (Build.VERSION.SDK_INT >= 30) stopTethering(instance, type) else stopTetheringLegacy(app.connectivity, type) } /** @@ -498,7 +490,7 @@ object TetheringManager { * Only [TetheringEventCallback.onTetheredInterfacesChanged] is supported on API 29-. */ fun registerTetheringEventCallbackCompat(context: Context, callback: TetheringEventCallback) { - if (BuildCompat.isAtLeastR()) { + if (Build.VERSION.SDK_INT >= 30) { registerTetheringEventCallback(null.makeExecutor(), callback) } else synchronized(callbackMap) { callbackMap.computeIfAbsent(callback) { @@ -509,7 +501,7 @@ object TetheringManager { } } fun unregisterTetheringEventCallbackCompat(context: Context, callback: TetheringEventCallback) { - if (BuildCompat.isAtLeastR()) { + if (Build.VERSION.SDK_INT >= 30) { unregisterTetheringEventCallback(callback) } else { val receiver = synchronized(callbackMap) { callbackMap.remove(callback) } ?: return @@ -545,7 +537,7 @@ object TetheringManager { } } fun tetherErrorMessage(error: Int): String { - if (BuildCompat.isAtLeastR()) try { + if (Build.VERSION.SDK_INT >= 30) try { tetherErrors.get(error)?.let { return it } } catch (e: ReflectiveOperationException) { Timber.w(e) @@ -557,6 +549,6 @@ object TetheringManager { if (Build.VERSION.SDK_INT >= 26) EXTRA_ACTIVE_TETHER else EXTRA_ACTIVE_TETHER_LEGACY) val Intent.localOnlyTetheredIfaces get() = if (Build.VERSION.SDK_INT >= 26) { 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() } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt index ffbf3bf7..18d9da8e 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt @@ -1,8 +1,8 @@ package be.mygod.vpnhotspot.net.monitor +import android.os.Build import android.system.ErrnoException import android.system.OsConstants -import androidx.core.os.BuildCompat import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.R 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 private val errorMatcher = "(^Cannot bind netlink socket: |Dump (was interrupted and may be inconsistent.|terminated)$)" .toRegex() - private val currentMode get() = Mode.valueOf(app.pref.getString(KEY, (if (BuildCompat.isAtLeastR()) - Mode.MonitorRoot else @Suppress("DEPRECATION") Mode.Poll).toString()) ?: "") + private val currentMode: Mode get() { + 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) { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApDialogFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApDialogFragment.kt index 995aa87e..b6e5ff51 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApDialogFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApDialogFragment.kt @@ -16,7 +16,6 @@ import android.widget.ArrayAdapter import androidx.annotation.RequiresApi import androidx.appcompat.app.AlertDialog import androidx.appcompat.widget.Toolbar -import androidx.core.os.BuildCompat import androidx.core.view.isGone import be.mygod.vpnhotspot.AlertDialogFragment import be.mygod.vpnhotspot.App.Companion.app @@ -128,7 +127,7 @@ class WifiApDialogFragment : AlertDialogFragment= 28) add(BandOption.BandAny) add(BandOption.Band2GHz) add(BandOption.Band5GHz) - if (BuildCompat.isAtLeastR()) add(BandOption.Band6GHz) + if (Build.VERSION.SDK_INT >= 30) add(BandOption.Band6GHz) } addAll(channels) } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApManager.kt index d5dbb793..1637077f 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApManager.kt @@ -3,8 +3,8 @@ package be.mygod.vpnhotspot.net.wifi import android.annotation.TargetApi import android.net.wifi.SoftApConfiguration import android.net.wifi.WifiManager +import android.os.Build import androidx.annotation.RequiresApi -import androidx.core.os.BuildCompat import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.net.wifi.SoftApConfigurationCompat.Companion.toCompat @@ -23,17 +23,15 @@ object WifiApManager { } var configuration: SoftApConfigurationCompat - get() = if (BuildCompat.isAtLeastR()) { - (getSoftApConfiguration(app.wifi) as SoftApConfiguration).toCompat() - } else @Suppress("DEPRECATION") { + get() = if (Build.VERSION.SDK_INT < 30) @Suppress("DEPRECATION") { (getWifiApConfiguration(app.wifi) as android.net.wifi.WifiConfiguration?)?.toCompat() ?: SoftApConfigurationCompat.empty() - } - set(value) = if (BuildCompat.isAtLeastR()) { - require(setSoftApConfiguration(app.wifi, value.toPlatform()) as Boolean) { "setSoftApConfiguration failed" } - } else @Suppress("DEPRECATION") { + } else (getSoftApConfiguration(app.wifi) as SoftApConfiguration).toCompat() + set(value) = if (Build.VERSION.SDK_INT < 30) @Suppress("DEPRECATION") { require(setWifiApConfiguration(app.wifi, value.toWifiConfiguration()) as Boolean) { "setWifiApConfiguration failed" } + } else require(setSoftApConfiguration(app.wifi, value.toPlatform()) as Boolean) { + "setSoftApConfiguration failed" } private val cancelLocalOnlyHotspotRequest by lazy {