Log p2p_supplicant if parsing failed
This commit is contained in:
@@ -4,6 +4,7 @@ import android.net.wifi.p2p.WifiP2pGroup
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.util.RootSession
|
import be.mygod.vpnhotspot.util.RootSession
|
||||||
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,7 +31,7 @@ class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress:
|
|||||||
override fun toString() = joinToString("\n")
|
override fun toString() = joinToString("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Parser(lines: List<String>) {
|
private class Parser(val lines: List<String>) {
|
||||||
private val iterator = lines.iterator()
|
private val iterator = lines.iterator()
|
||||||
lateinit var line: String
|
lateinit var line: String
|
||||||
lateinit var trimmed: String
|
lateinit var trimmed: String
|
||||||
@@ -45,36 +46,42 @@ class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress:
|
|||||||
val result = ArrayList<Any>()
|
val result = ArrayList<Any>()
|
||||||
var target: NetworkBlock? = null
|
var target: NetworkBlock? = null
|
||||||
val parser = Parser(it.execOutUnjoined("cat $confPath"))
|
val parser = Parser(it.execOutUnjoined("cat $confPath"))
|
||||||
while (parser.next()) {
|
try {
|
||||||
if (parser.trimmed.startsWith("network={")) {
|
while (parser.next()) {
|
||||||
val block = NetworkBlock()
|
if (parser.trimmed.startsWith("network={")) {
|
||||||
block.add(parser.line)
|
val block = NetworkBlock()
|
||||||
while (parser.next() && !parser.trimmed.startsWith('}')) {
|
block.add(parser.line)
|
||||||
if (parser.trimmed.startsWith("ssid=")) {
|
while (parser.next() && !parser.trimmed.startsWith('}')) {
|
||||||
check(block.ssidLine == null)
|
if (parser.trimmed.startsWith("ssid=")) {
|
||||||
block.ssidLine = block.size
|
check(block.ssidLine == null)
|
||||||
} else if (parser.trimmed.startsWith("mode=3")) block.groupOwner = true else {
|
block.ssidLine = block.size
|
||||||
val match = networkParser.find(parser.trimmed)
|
} else if (parser.trimmed.startsWith("mode=3")) block.groupOwner = true else {
|
||||||
if (match != null) if (match.groups[5] != null) {
|
val match = networkParser.find(parser.trimmed)
|
||||||
check(block.pskLine == null && block.psk == null)
|
if (match != null) if (match.groups[5] != null) {
|
||||||
block.psk = match.groupValues[5].apply { check(length in 8..63) }
|
check(block.pskLine == null && block.psk == null)
|
||||||
block.pskLine = block.size
|
block.psk = match.groupValues[5].apply { check(length in 8..63) }
|
||||||
} else if (match.groups[2] != null &&
|
block.pskLine = block.size
|
||||||
match.groupValues[2].equals(group.owner.deviceAddress ?: ownerAddress, true)) {
|
} else if (match.groups[2] != null &&
|
||||||
block.bssidMatches = true
|
match.groupValues[2].equals(group.owner.deviceAddress ?: ownerAddress, true)) {
|
||||||
|
block.bssidMatches = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
block.add(parser.line)
|
||||||
}
|
}
|
||||||
block.add(parser.line)
|
block.add(parser.line)
|
||||||
}
|
result.add(block)
|
||||||
block.add(parser.line)
|
if (block.bssidMatches && block.groupOwner && target == null) { // keep first only
|
||||||
result.add(block)
|
check(block.ssidLine != null && block.pskLine != null)
|
||||||
if (block.bssidMatches && block.groupOwner && target == null) { // keep first only
|
target = block
|
||||||
check(block.ssidLine != null && block.pskLine != null)
|
}
|
||||||
target = block
|
} else result.add(parser.line)
|
||||||
}
|
}
|
||||||
} else result.add(parser.line)
|
Pair(result, target!!)
|
||||||
|
} catch (e: RuntimeException) {
|
||||||
|
Timber.w("Failed to parse p2p_supplicant.conf, ownerAddress: $ownerAddress, P2P group: $group")
|
||||||
|
Timber.w(parser.lines.joinToString("\n"))
|
||||||
|
throw e
|
||||||
}
|
}
|
||||||
Pair(result, target!!)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val ssid = group.networkName
|
val ssid = group.networkName
|
||||||
|
|||||||
Reference in New Issue
Block a user