Support querying features via WifiManager
This commit is contained in:
@@ -299,6 +299,7 @@ Greylisted/blacklisted APIs or internal constants: (some constants are hardcoded
|
||||
* (since API 28) `Landroid/net/wifi/WifiManager;->WIFI_AP_STATE_FAILED:I,sdk,system-api,test-api`
|
||||
* (since API 30) `Landroid/net/wifi/WifiManager;->getSoftApConfiguration()Landroid/net/wifi/SoftApConfiguration;,sdk,system-api,test-api`
|
||||
* (prior to API 30) `Landroid/net/wifi/WifiManager;->getWifiApConfiguration()Landroid/net/wifi/WifiConfiguration;,sdk,system-api,test-api`
|
||||
* (since API 30) `Landroid/net/wifi/WifiManager;->isApMacRandomizationSupported()Z,sdk,system-api,test-api`
|
||||
* (since API 28) `Landroid/net/wifi/WifiManager;->registerSoftApCallback(Ljava/util/concurrent/Executor;Landroid/net/wifi/WifiManager$SoftApCallback;)V,sdk,system-api,test-api`
|
||||
* (since API 30) `Landroid/net/wifi/WifiManager;->setSoftApConfiguration(Landroid/net/wifi/SoftApConfiguration;)Z,sdk,system-api,test-api`
|
||||
* (prior to API 30) `Landroid/net/wifi/WifiManager;->setWifiApConfiguration(Landroid/net/wifi/WifiConfiguration;)Z,sdk,system-api,test-api`
|
||||
|
||||
@@ -28,10 +28,7 @@ import be.mygod.vpnhotspot.net.TetherType
|
||||
import be.mygod.vpnhotspot.net.TetheringManager
|
||||
import be.mygod.vpnhotspot.net.wifi.*
|
||||
import be.mygod.vpnhotspot.root.WifiApCommands
|
||||
import be.mygod.vpnhotspot.util.format
|
||||
import be.mygod.vpnhotspot.util.joinToSpanned
|
||||
import be.mygod.vpnhotspot.util.makeMacSpan
|
||||
import be.mygod.vpnhotspot.util.readableMessage
|
||||
import be.mygod.vpnhotspot.util.*
|
||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
@@ -203,7 +200,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
|
||||
val capability = SoftApCapability(parcel)
|
||||
val numClients = numClients
|
||||
val maxClients = capability.maxSupportedClients
|
||||
var supportedFeatures = capability.supportedFeatures
|
||||
var features = capability.supportedFeatures
|
||||
if (BuildCompat.isAtLeastS()) for ((flag, band) in arrayOf(
|
||||
SoftApCapability.SOFTAP_FEATURE_BAND_24G_SUPPORTED to SoftApConfigurationCompat.BAND_2GHZ,
|
||||
SoftApCapability.SOFTAP_FEATURE_BAND_5G_SUPPORTED to SoftApConfigurationCompat.BAND_5GHZ,
|
||||
@@ -212,17 +209,28 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
|
||||
)) {
|
||||
if (capability.getSupportedChannelList(band).isEmpty()) continue
|
||||
// reduce double reporting
|
||||
supportedFeatures = supportedFeatures and flag.inv()
|
||||
features = features and flag.inv()
|
||||
}
|
||||
val result = parent.resources.getQuantityText(R.plurals.tethering_manage_wifi_capabilities, numClients ?: 0)
|
||||
.format(locale, numClients ?: "?", maxClients, sequence {
|
||||
var features = supportedFeatures
|
||||
if (WifiApManager.isApMacRandomizationSupported) yield(parent.getText(
|
||||
R.string.tethering_manage_wifi_feature_ap_mac_randomization))
|
||||
if (Services.wifi.isStaApConcurrencySupported) yield(parent.getText(
|
||||
R.string.tethering_manage_wifi_feature_sta_ap_concurrency))
|
||||
if (BuildCompat.isAtLeastS()) {
|
||||
if (Services.wifi.isBridgedApConcurrencySupported) yield(parent.getText(
|
||||
R.string.tethering_manage_wifi_feature_bridged_ap_concurrency))
|
||||
if (Services.wifi.isStaBridgedApConcurrencySupported) yield(parent.getText(
|
||||
R.string.tethering_manage_wifi_feature_sta_bridged_ap_concurrency))
|
||||
}
|
||||
if (features != 0L) while (features != 0L) {
|
||||
val bit = features.takeLowestOneBit()
|
||||
yield(SoftApCapability.featureLookup(bit, true))
|
||||
features = features and bit.inv()
|
||||
} else yield(parent.getText(R.string.tethering_manage_wifi_no_features))
|
||||
}.joinToSpanned())
|
||||
}
|
||||
}.joinToSpanned().let {
|
||||
if (it.isEmpty()) parent.getText(R.string.tethering_manage_wifi_no_features) else it
|
||||
})
|
||||
if (BuildCompat.isAtLeastS()) {
|
||||
val list = SoftApConfigurationCompat.BAND_TYPES.map { band ->
|
||||
val channels = capability.getSupportedChannelList(band)
|
||||
|
||||
@@ -52,6 +52,13 @@ object WifiApManager {
|
||||
else -> false
|
||||
}
|
||||
|
||||
@get:RequiresApi(30)
|
||||
private val apMacRandomizationSupported by lazy {
|
||||
WifiManager::class.java.getDeclaredMethod("isApMacRandomizationSupported")
|
||||
}
|
||||
@get:RequiresApi(30)
|
||||
val isApMacRandomizationSupported get() = apMacRandomizationSupported(Services.wifi) as Boolean
|
||||
|
||||
private val getWifiApConfiguration by lazy { WifiManager::class.java.getDeclaredMethod("getWifiApConfiguration") }
|
||||
@Suppress("DEPRECATION")
|
||||
private val setWifiApConfiguration by lazy {
|
||||
|
||||
@@ -70,6 +70,10 @@
|
||||
<item quantity="other">已连接 %d 个设备</item>
|
||||
</plurals>
|
||||
<string name="tethering_manage_wifi_supported_channels">\n支持频道: %s</string>
|
||||
<string name="tethering_manage_wifi_feature_ap_mac_randomization">随机接入点 MAC</string>
|
||||
<string name="tethering_manage_wifi_feature_bridged_ap_concurrency">桥接 AP 并发</string>
|
||||
<string name="tethering_manage_wifi_feature_sta_ap_concurrency">STA/AP 并发</string>
|
||||
<string name="tethering_manage_wifi_feature_sta_bridged_ap_concurrency">STA/桥接 AP 并发</string>
|
||||
<string name="tethering_manage_wifi_no_features">无</string>
|
||||
<string name="tethering_manage_wifi_client_blocked">已屏蔽 %1$s:%2$s</string>
|
||||
<string name="tethering_manage_wifi_copy_mac">复制 MAC</string>
|
||||
|
||||
@@ -83,6 +83,10 @@
|
||||
<item quantity="other">%1d clients connected</item>
|
||||
</plurals>
|
||||
<string name="tethering_manage_wifi_supported_channels">\nSupported channels: %s</string>
|
||||
<string name="tethering_manage_wifi_feature_ap_mac_randomization">Randomized AP MAC</string>
|
||||
<string name="tethering_manage_wifi_feature_bridged_ap_concurrency">Bridged AP concurrency</string>
|
||||
<string name="tethering_manage_wifi_feature_sta_ap_concurrency">STA + AP concurrency</string>
|
||||
<string name="tethering_manage_wifi_feature_sta_bridged_ap_concurrency">STA + Bridged AP concurrency</string>
|
||||
<string name="tethering_manage_wifi_no_features">None</string>
|
||||
<string name="tethering_manage_wifi_client_blocked">Blocked %1$s: %2$s</string>
|
||||
<string name="tethering_manage_wifi_copy_mac">Copy MAC</string>
|
||||
|
||||
Reference in New Issue
Block a user