Support obtaining p2p randomization setting
This commit is contained in:
@@ -30,6 +30,7 @@ import be.mygod.vpnhotspot.net.MacAddressCompat
|
||||
import be.mygod.vpnhotspot.net.wifi.P2pSupplicantConfiguration
|
||||
import be.mygod.vpnhotspot.net.wifi.SoftApConfigurationCompat
|
||||
import be.mygod.vpnhotspot.net.wifi.WifiApDialogFragment
|
||||
import be.mygod.vpnhotspot.net.wifi.WifiApManager
|
||||
import be.mygod.vpnhotspot.util.ServiceForegroundConnector
|
||||
import be.mygod.vpnhotspot.util.formatAddresses
|
||||
import be.mygod.vpnhotspot.util.showAllowingStateLoss
|
||||
@@ -197,6 +198,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
||||
shutdownTimeoutMillis = RepeaterService.shutdownTimeoutMillis).apply {
|
||||
bssid = RepeaterService.deviceAddress
|
||||
setChannel(RepeaterService.operatingChannel, RepeaterService.operatingBand)
|
||||
setMacRandomizationEnabled(WifiApManager.p2pMacRandomizationSupported)
|
||||
} to false
|
||||
}
|
||||
} else binder?.let { binder ->
|
||||
@@ -206,13 +208,14 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
||||
securityType = SoftApConfiguration.SECURITY_TYPE_WPA2_PSK, // is not actually used
|
||||
isAutoShutdownEnabled = RepeaterService.isAutoShutdownEnabled,
|
||||
shutdownTimeoutMillis = RepeaterService.shutdownTimeoutMillis).run {
|
||||
setChannel(RepeaterService.operatingChannel)
|
||||
setMacRandomizationEnabled(WifiApManager.p2pMacRandomizationSupported)
|
||||
try {
|
||||
val config = P2pSupplicantConfiguration(group)
|
||||
config.init(binder.obtainDeviceAddress()?.toString())
|
||||
holder.config = config
|
||||
passphrase = config.psk
|
||||
bssid = config.bssid
|
||||
setChannel(RepeaterService.operatingChannel)
|
||||
this to false
|
||||
} catch (e: Exception) {
|
||||
if (e !is CancellationException) Timber.w(e)
|
||||
|
||||
@@ -46,7 +46,7 @@ class TetherTimeoutMonitor(private val timeout: Long = 0,
|
||||
val info = WifiApManager.resolvedActivity.activityInfo
|
||||
val resources = app.packageManager.getResourcesForApplication(info.applicationInfo)
|
||||
resources.getInteger(resources.findIdentifier("config_wifiFrameworkSoftApShutDownTimeoutMilliseconds",
|
||||
"integer", "com.android.wifi.resources", info.packageName))
|
||||
"integer", WifiApManager.RESOURCES_PACKAGE, info.packageName))
|
||||
}
|
||||
} catch (e: RuntimeException) {
|
||||
Timber.w(e)
|
||||
|
||||
@@ -343,6 +343,10 @@ data class SoftApConfigurationCompat(
|
||||
channels = SparseIntArray(1).apply { put(band, channel) }
|
||||
}
|
||||
|
||||
fun setMacRandomizationEnabled(enabled: Boolean) {
|
||||
macRandomizationSetting = if (enabled) RANDOMIZATION_PERSISTENT else RANDOMIZATION_NONE
|
||||
}
|
||||
|
||||
/**
|
||||
* Only single band/channel can be supplied on API 23-30
|
||||
*/
|
||||
|
||||
@@ -3,6 +3,7 @@ package be.mygod.vpnhotspot.net.wifi
|
||||
import android.annotation.TargetApi
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Resources
|
||||
import android.net.wifi.SoftApConfiguration
|
||||
import android.net.wifi.WifiManager
|
||||
import android.os.Build
|
||||
@@ -15,6 +16,7 @@ import be.mygod.vpnhotspot.net.wifi.SoftApConfigurationCompat.Companion.toCompat
|
||||
import be.mygod.vpnhotspot.util.ConstantLookup
|
||||
import be.mygod.vpnhotspot.util.Services
|
||||
import be.mygod.vpnhotspot.util.callSuper
|
||||
import be.mygod.vpnhotspot.util.findIdentifier
|
||||
import timber.log.Timber
|
||||
import java.lang.reflect.InvocationHandler
|
||||
import java.lang.reflect.Method
|
||||
@@ -27,6 +29,8 @@ object WifiApManager {
|
||||
*/
|
||||
@RequiresApi(30)
|
||||
private const val ACTION_RESOURCES_APK = "com.android.server.wifi.intent.action.SERVICE_WIFI_RESOURCES_APK"
|
||||
@RequiresApi(30)
|
||||
const val RESOURCES_PACKAGE = "com.android.wifi.resources"
|
||||
/**
|
||||
* Based on: https://android.googlesource.com/platform/frameworks/opt/net/wifi/+/000ad45/service/java/com/android/server/wifi/WifiContext.java#66
|
||||
*/
|
||||
@@ -34,6 +38,20 @@ object WifiApManager {
|
||||
val resolvedActivity get() = app.packageManager.queryIntentActivities(Intent(ACTION_RESOURCES_APK),
|
||||
PackageManager.MATCH_SYSTEM_ONLY).single()
|
||||
|
||||
private const val CONFIG_P2P_MAC_RANDOMIZATION_SUPPORTED = "config_wifi_p2p_mac_randomization_supported"
|
||||
val p2pMacRandomizationSupported get() = when (Build.VERSION.SDK_INT) {
|
||||
29 -> Resources.getSystem().run {
|
||||
getBoolean(getIdentifier(CONFIG_P2P_MAC_RANDOMIZATION_SUPPORTED, "bool", "android"))
|
||||
}
|
||||
in 30..Int.MAX_VALUE -> @TargetApi(30) {
|
||||
val info = resolvedActivity.activityInfo
|
||||
val resources = app.packageManager.getResourcesForApplication(info.applicationInfo)
|
||||
resources.getBoolean(resources.findIdentifier(CONFIG_P2P_MAC_RANDOMIZATION_SUPPORTED, "bool",
|
||||
RESOURCES_PACKAGE, info.packageName))
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
|
||||
private val getWifiApConfiguration by lazy { WifiManager::class.java.getDeclaredMethod("getWifiApConfiguration") }
|
||||
@Suppress("DEPRECATION")
|
||||
private val setWifiApConfiguration by lazy {
|
||||
|
||||
Reference in New Issue
Block a user