Handle fallback wifi p2p configuration
This commit is contained in:
@@ -26,6 +26,7 @@ import androidx.lifecycle.lifecycleScope
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import be.mygod.vpnhotspot.*
|
import be.mygod.vpnhotspot.*
|
||||||
import be.mygod.vpnhotspot.databinding.ListitemRepeaterBinding
|
import be.mygod.vpnhotspot.databinding.ListitemRepeaterBinding
|
||||||
|
import be.mygod.vpnhotspot.net.MacAddressCompat
|
||||||
import be.mygod.vpnhotspot.net.wifi.SoftApConfigurationCompat
|
import be.mygod.vpnhotspot.net.wifi.SoftApConfigurationCompat
|
||||||
import be.mygod.vpnhotspot.net.wifi.P2pSupplicantConfiguration
|
import be.mygod.vpnhotspot.net.wifi.P2pSupplicantConfiguration
|
||||||
import be.mygod.vpnhotspot.net.wifi.WifiApDialogFragment
|
import be.mygod.vpnhotspot.net.wifi.WifiApDialogFragment
|
||||||
@@ -142,9 +143,9 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun configure() = parent.viewLifecycleOwner.lifecycleScope.launchWhenCreated {
|
fun configure() = parent.viewLifecycleOwner.lifecycleScope.launchWhenCreated {
|
||||||
getConfiguration()?.let { config ->
|
getConfiguration()?.let { (config, readOnly) ->
|
||||||
WifiApDialogFragment().apply {
|
WifiApDialogFragment().apply {
|
||||||
arg(WifiApDialogFragment.Arg(config, p2pMode = true))
|
arg(WifiApDialogFragment.Arg(config, readOnly, true))
|
||||||
key(this@RepeaterManager.javaClass.name)
|
key(this@RepeaterManager.javaClass.name)
|
||||||
}.showAllowingStateLoss(parent.parentFragmentManager)
|
}.showAllowingStateLoss(parent.parentFragmentManager)
|
||||||
}
|
}
|
||||||
@@ -176,7 +177,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
|||||||
}
|
}
|
||||||
|
|
||||||
@MainThread
|
@MainThread
|
||||||
private suspend fun getConfiguration(): SoftApConfigurationCompat? {
|
private suspend fun getConfiguration(): Pair<SoftApConfigurationCompat, Boolean>? {
|
||||||
if (RepeaterService.safeMode) {
|
if (RepeaterService.safeMode) {
|
||||||
val networkName = RepeaterService.networkName
|
val networkName = RepeaterService.networkName
|
||||||
val passphrase = RepeaterService.passphrase
|
val passphrase = RepeaterService.passphrase
|
||||||
@@ -193,25 +194,29 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
|||||||
}
|
}
|
||||||
channel = RepeaterService.operatingChannel
|
channel = RepeaterService.operatingChannel
|
||||||
bssid = RepeaterService.deviceAddress
|
bssid = RepeaterService.deviceAddress
|
||||||
}
|
} to false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val group = binder?.group
|
val group = binder?.group
|
||||||
if (group != null) try {
|
if (group != null) return SoftApConfigurationCompat.empty().run {
|
||||||
val config = withContext(Dispatchers.Default) {
|
ssid = group.networkName
|
||||||
P2pSupplicantConfiguration(group, RepeaterService.lastMac)
|
securityType = SoftApConfiguration.SECURITY_TYPE_WPA2_PSK // is not actually used
|
||||||
}
|
band = SoftApConfigurationCompat.BAND_ANY
|
||||||
holder.config = config
|
channel = RepeaterService.operatingChannel
|
||||||
return SoftApConfigurationCompat.empty().apply {
|
try {
|
||||||
ssid = group.networkName
|
val config = withContext(Dispatchers.Default) {
|
||||||
securityType = SoftApConfiguration.SECURITY_TYPE_WPA2_PSK // is not actually used
|
P2pSupplicantConfiguration(group, RepeaterService.lastMac)
|
||||||
|
}
|
||||||
|
holder.config = config
|
||||||
passphrase = config.psk
|
passphrase = config.psk
|
||||||
band = SoftApConfigurationCompat.BAND_ANY
|
|
||||||
channel = RepeaterService.operatingChannel
|
|
||||||
bssid = config.bssid
|
bssid = config.bssid
|
||||||
|
this to false
|
||||||
|
} catch (e: RuntimeException) {
|
||||||
|
Timber.w(e)
|
||||||
|
passphrase = group.passphrase
|
||||||
|
bssid = group.owner?.deviceAddress?.let(MacAddressCompat::fromString)
|
||||||
|
this to true
|
||||||
}
|
}
|
||||||
} catch (e: RuntimeException) {
|
|
||||||
Timber.w(e)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SmartSnackbar.make(R.string.repeater_configure_failure).show()
|
SmartSnackbar.make(R.string.repeater_configure_failure).show()
|
||||||
@@ -229,7 +234,8 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
|||||||
}
|
}
|
||||||
} else holder.config?.let { master ->
|
} else holder.config?.let { master ->
|
||||||
val binder = binder
|
val binder = binder
|
||||||
if (binder?.group?.networkName != config.ssid || master.psk != config.passphrase || master.bssid != config.bssid) try {
|
if (binder?.group?.networkName != config.ssid || master.psk != config.passphrase ||
|
||||||
|
master.bssid != config.bssid) try {
|
||||||
withContext(Dispatchers.Default) { master.update(config.ssid!!, config.passphrase!!, config.bssid) }
|
withContext(Dispatchers.Default) { master.update(config.ssid!!, config.passphrase!!, config.bssid) }
|
||||||
(this.binder ?: binder)?.group = null
|
(this.binder ?: binder)?.group = null
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
Reference in New Issue
Block a user