Drop support for old Android 12 betas

This commit is contained in:
Mygod
2021-07-24 20:33:30 -04:00
parent 37eeeb4324
commit b03303c73a
7 changed files with 40 additions and 43 deletions

View File

@@ -4,10 +4,10 @@ import android.content.ComponentName
import android.content.IntentFilter import android.content.IntentFilter
import android.content.ServiceConnection import android.content.ServiceConnection
import android.net.wifi.p2p.WifiP2pDevice import android.net.wifi.p2p.WifiP2pDevice
import android.os.Build
import android.os.IBinder import android.os.IBinder
import android.os.Parcelable import android.os.Parcelable
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.core.os.BuildCompat
import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
@@ -87,10 +87,10 @@ class ClientViewModel : ViewModel(), ServiceConnection, IpNeighbourMonitor.Callb
override fun onStart(owner: LifecycleOwner) { override fun onStart(owner: LifecycleOwner) {
app.registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED)) app.registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED))
IpNeighbourMonitor.registerCallback(this, false) IpNeighbourMonitor.registerCallback(this, false)
if (BuildCompat.isAtLeastS()) WifiApCommands.registerSoftApCallback(this) if (Build.VERSION.SDK_INT >= 31) WifiApCommands.registerSoftApCallback(this)
} }
override fun onStop(owner: LifecycleOwner) { override fun onStop(owner: LifecycleOwner) {
if (BuildCompat.isAtLeastS()) WifiApCommands.unregisterSoftApCallback(this) if (Build.VERSION.SDK_INT >= 31) WifiApCommands.unregisterSoftApCallback(this)
IpNeighbourMonitor.unregisterCallback(this) IpNeighbourMonitor.unregisterCallback(this)
app.unregisterReceiver(receiver) app.unregisterReceiver(receiver)
} }

View File

@@ -12,7 +12,6 @@ import android.content.IntentFilter
import android.os.Build import android.os.Build
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
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
@@ -91,7 +90,7 @@ class BluetoothTethering(context: Context, val stateListener: () -> Unit) :
check(adapter.getProfileProxy(context, this, PAN)) check(adapter.getProfileProxy(context, this, PAN))
proxyCreated = true proxyCreated = true
} catch (e: SecurityException) { } catch (e: SecurityException) {
if (BuildCompat.isAtLeastS()) Timber.d(e.readableMessage) else Timber.w(e) if (Build.VERSION.SDK_INT >= 31) Timber.d(e.readableMessage) else Timber.w(e)
activeFailureCause = e activeFailureCause = e
} }
} }

View File

@@ -15,7 +15,6 @@ import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.core.os.BuildCompat
import androidx.core.view.updatePaddingRelative import androidx.core.view.updatePaddingRelative
import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
@@ -198,7 +197,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
val numClients = numClients val numClients = numClients
val maxClients = capability.maxSupportedClients val maxClients = capability.maxSupportedClients
var features = capability.supportedFeatures var features = capability.supportedFeatures
if (BuildCompat.isAtLeastS()) for ((flag, band) in arrayOf( if (Build.VERSION.SDK_INT >= 31) for ((flag, band) in arrayOf(
SoftApCapability.SOFTAP_FEATURE_BAND_24G_SUPPORTED to SoftApConfigurationCompat.BAND_2GHZ, SoftApCapability.SOFTAP_FEATURE_BAND_24G_SUPPORTED to SoftApConfigurationCompat.BAND_2GHZ,
SoftApCapability.SOFTAP_FEATURE_BAND_5G_SUPPORTED to SoftApConfigurationCompat.BAND_5GHZ, SoftApCapability.SOFTAP_FEATURE_BAND_5G_SUPPORTED to SoftApConfigurationCompat.BAND_5GHZ,
SoftApCapability.SOFTAP_FEATURE_BAND_6G_SUPPORTED to SoftApConfigurationCompat.BAND_6GHZ, SoftApCapability.SOFTAP_FEATURE_BAND_6G_SUPPORTED to SoftApConfigurationCompat.BAND_6GHZ,
@@ -214,7 +213,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
R.string.tethering_manage_wifi_feature_ap_mac_randomization)) R.string.tethering_manage_wifi_feature_ap_mac_randomization))
if (Services.wifi.isStaApConcurrencySupported) yield(parent.getText( if (Services.wifi.isStaApConcurrencySupported) yield(parent.getText(
R.string.tethering_manage_wifi_feature_sta_ap_concurrency)) R.string.tethering_manage_wifi_feature_sta_ap_concurrency))
if (BuildCompat.isAtLeastS()) { if (Build.VERSION.SDK_INT >= 31) {
if (Services.wifi.isBridgedApConcurrencySupported) yield(parent.getText( if (Services.wifi.isBridgedApConcurrencySupported) yield(parent.getText(
R.string.tethering_manage_wifi_feature_bridged_ap_concurrency)) R.string.tethering_manage_wifi_feature_bridged_ap_concurrency))
if (Services.wifi.isStaBridgedApConcurrencySupported) yield(parent.getText( if (Services.wifi.isStaBridgedApConcurrencySupported) yield(parent.getText(
@@ -228,7 +227,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
}.joinToSpanned().let { }.joinToSpanned().let {
if (it.isEmpty()) parent.getText(R.string.tethering_manage_wifi_no_features) else it if (it.isEmpty()) parent.getText(R.string.tethering_manage_wifi_no_features) else it
}) })
if (BuildCompat.isAtLeastS()) { if (Build.VERSION.SDK_INT >= 31) {
val list = SoftApConfigurationCompat.BAND_TYPES.map { band -> val list = SoftApConfigurationCompat.BAND_TYPES.map { band ->
val channels = capability.getSupportedChannelList(band) val channels = capability.getSupportedChannelList(band)
if (channels.isNotEmpty()) StringBuilder().apply { if (channels.isNotEmpty()) StringBuilder().apply {
@@ -272,7 +271,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
val frequency = info.frequency val frequency = info.frequency
val channel = SoftApConfigurationCompat.frequencyToChannel(frequency) val channel = SoftApConfigurationCompat.frequencyToChannel(frequency)
val bandwidth = SoftApInfo.channelWidthLookup(info.bandwidth, true) val bandwidth = SoftApInfo.channelWidthLookup(info.bandwidth, true)
if (BuildCompat.isAtLeastS()) { if (Build.VERSION.SDK_INT >= 31) {
var bssid = makeMacSpan(info.bssid.toString()) var bssid = makeMacSpan(info.bssid.toString())
info.apInstanceIdentifier?.let { // take the fast route if possible info.apInstanceIdentifier?.let { // take the fast route if possible
bssid = if (bssid is String) "$bssid%$it" else SpannableStringBuilder(bssid).append("%$it") bssid = if (bssid is String) "$bssid%$it" else SpannableStringBuilder(bssid).append("%$it")
@@ -315,7 +314,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
onTetheringStarted() // force flush onTetheringStarted() // force flush
} }
override fun onResume(owner: LifecycleOwner) { override fun onResume(owner: LifecycleOwner) {
if (!BuildCompat.isAtLeastS() || parent.requireContext().checkSelfPermission( if (Build.VERSION.SDK_INT < 31 || parent.requireContext().checkSelfPermission(
Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) { Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
tethering.ensureInit(parent.requireContext()) tethering.ensureInit(parent.requireContext())
} else if (parent.shouldShowRequestPermissionRationale(Manifest.permission.BLUETOOTH_CONNECT)) { } else if (parent.shouldShowRequestPermissionRationale(Manifest.permission.BLUETOOTH_CONNECT)) {

View File

@@ -8,7 +8,6 @@ import android.os.Build
import android.os.Parcelable import android.os.Parcelable
import android.util.SparseIntArray import android.util.SparseIntArray
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.core.os.BuildCompat
import be.mygod.vpnhotspot.net.MacAddressCompat import be.mygod.vpnhotspot.net.MacAddressCompat
import be.mygod.vpnhotspot.net.MacAddressCompat.Companion.toCompat import be.mygod.vpnhotspot.net.MacAddressCompat.Companion.toCompat
import be.mygod.vpnhotspot.net.monitor.TetherTimeoutMonitor import be.mygod.vpnhotspot.net.monitor.TetherTimeoutMonitor
@@ -64,7 +63,7 @@ data class SoftApConfigurationCompat(
const val BAND_60GHZ = 8 const val BAND_60GHZ = 8
const val BAND_LEGACY = BAND_2GHZ or BAND_5GHZ const val BAND_LEGACY = BAND_2GHZ or BAND_5GHZ
val BAND_TYPES by lazy { val BAND_TYPES by lazy {
if (BuildCompat.isAtLeastS()) try { if (Build.VERSION.SDK_INT >= 31) try {
return@lazy UnblockCentral.SoftApConfiguration_BAND_TYPES return@lazy UnblockCentral.SoftApConfiguration_BAND_TYPES
} catch (e: ReflectiveOperationException) { } catch (e: ReflectiveOperationException) {
Timber.w(e) Timber.w(e)
@@ -314,25 +313,26 @@ data class SoftApConfigurationCompat(
@RequiresApi(30) @RequiresApi(30)
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
fun SoftApConfiguration.toCompat() = SoftApConfigurationCompat( fun SoftApConfiguration.toCompat() = SoftApConfigurationCompat(
ssid, ssid,
bssid?.toCompat()?.addr, bssid?.toCompat()?.addr,
passphrase, passphrase,
isHiddenSsid, isHiddenSsid,
if (BuildCompat.isAtLeastS()) getChannels(this) as SparseIntArray else SparseIntArray(1).also { if (Build.VERSION.SDK_INT >= 31) getChannels(this) as SparseIntArray else SparseIntArray(1).also {
it.append(getBand(this) as Int, getChannel(this) as Int) it.append(getBand(this) as Int, getChannel(this) as Int)
}, },
securityType, securityType,
getMaxNumberOfClients(this) as Int, getMaxNumberOfClients(this) as Int,
isAutoShutdownEnabled(this) as Boolean, isAutoShutdownEnabled(this) as Boolean,
getShutdownTimeoutMillis(this) as Long, getShutdownTimeoutMillis(this) as Long,
isClientControlByUserEnabled(this) as Boolean, isClientControlByUserEnabled(this) as Boolean,
getBlockedClientList(this) as List<MacAddress>, getBlockedClientList(this) as List<MacAddress>,
getAllowedClientList(this) as List<MacAddress>, getAllowedClientList(this) as List<MacAddress>,
if (BuildCompat.isAtLeastS()) getMacRandomizationSetting(this) as Int else RANDOMIZATION_PERSISTENT, if (Build.VERSION.SDK_INT >= 31) getMacRandomizationSetting(this) as Int else RANDOMIZATION_PERSISTENT,
!BuildCompat.isAtLeastS() || isBridgedModeOpportunisticShutdownEnabled(this) as Boolean, Build.VERSION.SDK_INT < 31 || isBridgedModeOpportunisticShutdownEnabled(this) as Boolean,
!BuildCompat.isAtLeastS() || isIeee80211axEnabled(this) as Boolean, Build.VERSION.SDK_INT < 31 || isIeee80211axEnabled(this) as Boolean,
!BuildCompat.isAtLeastS() || isUserConfiguration(this) as Boolean, Build.VERSION.SDK_INT < 31 || isUserConfiguration(this) as Boolean,
this) this,
)
} }
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@@ -438,7 +438,7 @@ data class SoftApConfigurationCompat(
setSsid(builder, ssid) setSsid(builder, ssid)
setPassphrase(builder, if (securityType == SoftApConfiguration.SECURITY_TYPE_OPEN) null else passphrase, setPassphrase(builder, if (securityType == SoftApConfiguration.SECURITY_TYPE_OPEN) null else passphrase,
securityType) securityType)
if (BuildCompat.isAtLeastS()) setChannels(builder, channels) else { if (Build.VERSION.SDK_INT >= 31) setChannels(builder, channels) else {
val (band, channel) = requireSingleBand() val (band, channel) = requireSingleBand()
if (channel == 0) setBand(builder, band) else setChannel(builder, channel, band) if (channel == 0) setBand(builder, band) else setChannel(builder, channel, band)
} }
@@ -450,7 +450,7 @@ data class SoftApConfigurationCompat(
setHiddenSsid(builder, isHiddenSsid) setHiddenSsid(builder, isHiddenSsid)
setAllowedClientList(builder, allowedClientList) setAllowedClientList(builder, allowedClientList)
setBlockedClientList(builder, blockedClientList) setBlockedClientList(builder, blockedClientList)
if (BuildCompat.isAtLeastS()) { if (Build.VERSION.SDK_INT >= 31) {
setMacRandomizationSetting(builder, macRandomizationSetting) setMacRandomizationSetting(builder, macRandomizationSetting)
setBridgedModeOpportunisticShutdownEnabled(builder, isBridgedModeOpportunisticShutdownEnabled) setBridgedModeOpportunisticShutdownEnabled(builder, isBridgedModeOpportunisticShutdownEnabled)
setIeee80211axEnabled(builder, isIeee80211axEnabled) setIeee80211axEnabled(builder, isIeee80211axEnabled)

View File

@@ -20,7 +20,6 @@ import android.widget.Toast
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.librootkotlinx.toByteArray import be.mygod.librootkotlinx.toByteArray
import be.mygod.librootkotlinx.toParcelable import be.mygod.librootkotlinx.toParcelable
@@ -117,7 +116,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
val channel = (spinner.selectedItem as ChannelOption?)?.channel val channel = (spinner.selectedItem as ChannelOption?)?.channel
if (channel != null && channel >= 0) channels.append(band, channel) if (channel != null && channel >= 0) channels.append(band, channel)
} }
if (!arg.p2pMode && BuildCompat.isAtLeastS() && dialogView.bridgedMode.isChecked) { if (!arg.p2pMode && Build.VERSION.SDK_INT >= 31 && dialogView.bridgedMode.isChecked) {
this.channels = channels this.channels = channels
} else optimizeChannels(channels) } else optimizeChannels(channels)
} }
@@ -179,7 +178,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
dialogView.band5G.configure(currentChannels5G) dialogView.band5G.configure(currentChannels5G)
if (Build.VERSION.SDK_INT >= 30 && !arg.p2pMode) dialogView.band6G.configure(channels6G) if (Build.VERSION.SDK_INT >= 30 && !arg.p2pMode) dialogView.band6G.configure(channels6G)
else dialogView.bandWrapper6G.isGone = true else dialogView.bandWrapper6G.isGone = true
if (BuildCompat.isAtLeastS() && !arg.p2pMode) dialogView.band60G.configure(channels60G) else { if (Build.VERSION.SDK_INT >= 31 && !arg.p2pMode) dialogView.band60G.configure(channels60G) else {
dialogView.bandWrapper60G.isGone = true dialogView.bandWrapper60G.isGone = true
dialogView.bridgedMode.isGone = true dialogView.bridgedMode.isGone = true
dialogView.bridgedModeOpportunisticShutdown.isGone = true dialogView.bridgedModeOpportunisticShutdown.isGone = true
@@ -193,8 +192,8 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
dialogView.bssid.addTextChangedListener(this@WifiApDialogFragment) dialogView.bssid.addTextChangedListener(this@WifiApDialogFragment)
if (arg.p2pMode) dialogView.hiddenSsid.isGone = true if (arg.p2pMode) dialogView.hiddenSsid.isGone = true
if (arg.p2pMode && Build.VERSION.SDK_INT >= 29) dialogView.macRandomization.isEnabled = false if (arg.p2pMode && Build.VERSION.SDK_INT >= 29) dialogView.macRandomization.isEnabled = false
else if (arg.p2pMode || !BuildCompat.isAtLeastS()) dialogView.macRandomization.isGone = true else if (arg.p2pMode || Build.VERSION.SDK_INT < 31) dialogView.macRandomization.isGone = true
if (arg.p2pMode || !BuildCompat.isAtLeastS()) { if (arg.p2pMode || Build.VERSION.SDK_INT < 31) {
dialogView.ieee80211ax.isGone = true dialogView.ieee80211ax.isGone = true
dialogView.userConfig.isGone = true dialogView.userConfig.isGone = true
} }
@@ -302,7 +301,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
else -> option5G is ChannelOption.Disabled else -> option5G is ChannelOption.Disabled
} }
} }
Build.VERSION.SDK_INT == 30 && !BuildCompat.isAtLeastS() -> { Build.VERSION.SDK_INT == 30 -> {
var expected = 1 var expected = 1
var set = 0 var set = 0
for (s in arrayOf(dialogView.band2G, dialogView.band5G, dialogView.band6G)) when (s.selectedItem) { for (s in arrayOf(dialogView.band2G, dialogView.band5G, dialogView.band6G)) when (s.selectedItem) {

View File

@@ -287,7 +287,7 @@ object WifiApManager {
if (noArgs != 1) Timber.w("Unexpected args for $name: ${args?.contentToString()}") if (noArgs != 1) Timber.w("Unexpected args for $name: ${args?.contentToString()}")
val arg = args!![0] val arg = args!![0]
if (arg is List<*>) { if (arg is List<*>) {
if (!BuildCompat.isAtLeastS()) Timber.w(Exception("Unexpected onInfoChanged API 31+")) if (Build.VERSION.SDK_INT < 31) Timber.w(Exception("Unexpected onInfoChanged API 31+"))
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
callback.onInfoChanged(arg as List<Parcelable>) callback.onInfoChanged(arg as List<Parcelable>)
} else { } else {

View File

@@ -2,9 +2,9 @@ package be.mygod.vpnhotspot.root
import android.annotation.TargetApi import android.annotation.TargetApi
import android.content.ClipData import android.content.ClipData
import android.os.Build
import android.os.Parcelable import android.os.Parcelable
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.core.os.BuildCompat
import be.mygod.librootkotlinx.ParcelableBoolean import be.mygod.librootkotlinx.ParcelableBoolean
import be.mygod.librootkotlinx.RootCommand import be.mygod.librootkotlinx.RootCommand
import be.mygod.librootkotlinx.RootCommandChannel import be.mygod.librootkotlinx.RootCommandChannel
@@ -129,7 +129,7 @@ object WifiApCommands {
val client = WifiClient(parcel.client) val client = WifiClient(parcel.client)
val macAddress = client.macAddress val macAddress = client.macAddress
var name = macAddress.toString() var name = macAddress.toString()
if (BuildCompat.isAtLeastS()) client.apInstanceIdentifier?.let { name += "%$it" } if (Build.VERSION.SDK_INT >= 31) client.apInstanceIdentifier?.let { name += "%$it" }
val reason = WifiApManager.clientBlockLookup(parcel.blockedReason, true) val reason = WifiApManager.clientBlockLookup(parcel.blockedReason, true)
Timber.i("$name blocked from connecting: $reason (${parcel.blockedReason})") Timber.i("$name blocked from connecting: $reason (${parcel.blockedReason})")
SmartSnackbar.make(app.getString(R.string.tethering_manage_wifi_client_blocked, name, reason)).apply { SmartSnackbar.make(app.getString(R.string.tethering_manage_wifi_client_blocked, name, reason)).apply {