Allow user to skip specifying BSSID

This commit is contained in:
Mygod
2020-06-14 06:32:10 +08:00
parent 33d7105acf
commit d98333d35e
2 changed files with 6 additions and 4 deletions

View File

@@ -231,7 +231,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
} else holder.config?.let { master ->
val binder = binder
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
} catch (e: Exception) {
Timber.w(e)

View File

@@ -144,13 +144,15 @@ class P2pSupplicantConfiguration(private val group: WifiP2pGroup?, vararg ownerA
val psk = group?.passphrase ?: content.target.psk!!
val bssid = MacAddressCompat.fromString(content.target.bssid!!)
fun update(ssid: String, psk: String, bssid: MacAddressCompat) {
fun update(ssid: String, psk: String, bssid: MacAddressCompat?) {
val (lines, block, persistentMacLine, legacy) = content
persistentMacLine?.let { lines[it] = PERSISTENT_MAC + bssid }
block[block.ssidLine!!] = "\tssid=" + ssid.toByteArray()
.joinToString("") { (it.toInt() and 255).toString(16).padStart(2, '0') }
block[block.pskLine!!] = "\tpsk=\"$psk\"" // no control chars or weird stuff
if (bssid != null) {
persistentMacLine?.let { lines[it] = PERSISTENT_MAC + bssid }
block[block.bssidLine!!] = "\tbssid=$bssid"
}
val tempFile = File.createTempFile("vpnhotspot-", ".conf", app.deviceStorage.cacheDir)
try {
tempFile.printWriter().use { writer ->