Try both p2p_supplicant.conf paths for Project Treble
This commit is contained in:
@@ -164,6 +164,6 @@ If some of these are unavailable, you can alternatively install a recent version
|
|||||||
|
|
||||||
Wi-Fi driver `wpa_supplicant`:
|
Wi-Fi driver `wpa_supplicant`:
|
||||||
|
|
||||||
* P2P configuration file is assumed to be saved to `/data/misc/wifi/p2p_supplicant.conf` or
|
* P2P configuration file is assumed to be saved to `/data/vendor/wifi/wpa/p2p_supplicant.conf` or
|
||||||
`/data/vendor/wifi/wpa/p2p_supplicant.conf` for API 28+ and have reasonable format;
|
`/data/misc/wifi/p2p_supplicant.conf` and have reasonable format;
|
||||||
* Android system is expected to restart `wpa_supplicant` after it crashes.
|
* Android system is expected to restart `wpa_supplicant` after it crashes.
|
||||||
|
|||||||
@@ -64,7 +64,13 @@ object TrafficRecorder {
|
|||||||
|
|
||||||
private fun doUpdate(timestamp: Long) {
|
private fun doUpdate(timestamp: Long) {
|
||||||
val oldRecords = LongSparseArray<TrafficRecord>()
|
val oldRecords = LongSparseArray<TrafficRecord>()
|
||||||
loop@ for (line in RootSession.use { it.execOutUnjoinedWithWait("$IPTABLES -nvx -L vpnhotspot_fwd").drop(2) }) {
|
loop@ for (line in RootSession.use {
|
||||||
|
val command = "$IPTABLES -nvx -L vpnhotspot_fwd"
|
||||||
|
val result = it.execQuiet(command)
|
||||||
|
val message = it.checkOutput(command, result, false, false)
|
||||||
|
if (result.err.isNotEmpty()) Timber.i(message)
|
||||||
|
result.out.drop(2)
|
||||||
|
}) {
|
||||||
val columns = line.split("\\s+".toRegex()).filter { it.isNotEmpty() }
|
val columns = line.split("\\s+".toRegex()).filter { it.isNotEmpty() }
|
||||||
try {
|
try {
|
||||||
check(columns.size >= 9)
|
check(columns.size >= 9)
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ import java.io.File
|
|||||||
class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress: String?) {
|
class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress: String?) {
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "P2pSupplicantConfiguration"
|
private const val TAG = "P2pSupplicantConfiguration"
|
||||||
|
private const val CONF_PATH_TREBLE = "/data/vendor/wifi/wpa/p2p_supplicant.conf"
|
||||||
|
private const val CONF_PATH_LEGACY = "/data/misc/wifi/p2p_supplicant.conf"
|
||||||
private val networkParser =
|
private val networkParser =
|
||||||
"^(bssid=(([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2})|psk=(ext:|\"(.*)\"|[0-9a-fA-F]{64}\$))".toRegex()
|
"^(bssid=(([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2})|psk=(ext:|\"(.*)\"|[0-9a-fA-F]{64}\$))".toRegex()
|
||||||
private val whitespaceMatcher = "\\s+".toRegex()
|
private val whitespaceMatcher = "\\s+".toRegex()
|
||||||
private val confPath = if (Build.VERSION.SDK_INT >= 28)
|
|
||||||
"/data/vendor/wifi/wpa/p2p_supplicant.conf" else "/data/misc/wifi/p2p_supplicant.conf"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class NetworkBlock : ArrayList<String>() {
|
private class NetworkBlock : ArrayList<String>() {
|
||||||
@@ -46,7 +46,10 @@ class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress:
|
|||||||
RootSession.use {
|
RootSession.use {
|
||||||
val result = ArrayList<Any>()
|
val result = ArrayList<Any>()
|
||||||
var target: NetworkBlock? = null
|
var target: NetworkBlock? = null
|
||||||
val parser = Parser(it.execOutUnjoined("cat $confPath"))
|
val command = "cat $CONF_PATH_TREBLE || cat $CONF_PATH_LEGACY"
|
||||||
|
val shell = it.execQuiet(command)
|
||||||
|
it.checkOutput(command, shell, false, false)
|
||||||
|
val parser = Parser(shell.out)
|
||||||
try {
|
try {
|
||||||
while (parser.next()) {
|
while (parser.next()) {
|
||||||
if (parser.trimmed.startsWith("network={")) {
|
if (parser.trimmed.startsWith("network={")) {
|
||||||
@@ -77,7 +80,7 @@ class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress:
|
|||||||
}
|
}
|
||||||
} else result.add(parser.line)
|
} else result.add(parser.line)
|
||||||
}
|
}
|
||||||
Pair(result, target!!)
|
Triple(result, target!!, shell.err.isNotEmpty())
|
||||||
} catch (e: RuntimeException) {
|
} catch (e: RuntimeException) {
|
||||||
DebugHelper.setString(TAG, parser.lines.joinToString("\n"))
|
DebugHelper.setString(TAG, parser.lines.joinToString("\n"))
|
||||||
DebugHelper.setString("$TAG.ownerAddress", ownerAddress)
|
DebugHelper.setString("$TAG.ownerAddress", ownerAddress)
|
||||||
@@ -89,7 +92,7 @@ class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress:
|
|||||||
val psk = group.passphrase ?: content.second.psk!!
|
val psk = group.passphrase ?: content.second.psk!!
|
||||||
|
|
||||||
fun update(ssid: String, psk: String) {
|
fun update(ssid: String, psk: String) {
|
||||||
val (lines, block) = content
|
val (lines, block, legacy) = content
|
||||||
block[block.ssidLine!!] = "\tssid=" + ssid.toByteArray()
|
block[block.ssidLine!!] = "\tssid=" + ssid.toByteArray()
|
||||||
.joinToString("") { (it.toInt() and 255).toString(16).padStart(2, '0') }
|
.joinToString("") { (it.toInt() and 255).toString(16).padStart(2, '0') }
|
||||||
block[block.pskLine!!] = "\tpsk=\"$psk\"" // no control chars or weird stuff
|
block[block.pskLine!!] = "\tpsk=\"$psk\"" // no control chars or weird stuff
|
||||||
@@ -100,7 +103,7 @@ class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress:
|
|||||||
}
|
}
|
||||||
// pkill not available on Lollipop. Source: https://android.googlesource.com/platform/system/core/+/master/shell_and_utilities/README.md
|
// pkill not available on Lollipop. Source: https://android.googlesource.com/platform/system/core/+/master/shell_and_utilities/README.md
|
||||||
RootSession.use {
|
RootSession.use {
|
||||||
it.exec("cat ${tempFile.absolutePath} > $confPath")
|
it.exec("cat ${tempFile.absolutePath} > ${if (legacy) CONF_PATH_LEGACY else CONF_PATH_TREBLE}")
|
||||||
if (Build.VERSION.SDK_INT >= 23) it.exec("pkill wpa_supplicant") else {
|
if (Build.VERSION.SDK_INT >= 23) it.exec("pkill wpa_supplicant") else {
|
||||||
val result = it.execOut("ps | grep wpa_supplicant").split(whitespaceMatcher)
|
val result = it.execOut("ps | grep wpa_supplicant").split(whitespaceMatcher)
|
||||||
check(result.size >= 2) { "wpa_supplicant not found, please toggle Airplane mode manually" }
|
check(result.size >= 2) { "wpa_supplicant not found, please toggle Airplane mode manually" }
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ class RootSession : AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class UnexpectedOutputException(msg: String) : RuntimeException(msg)
|
class UnexpectedOutputException(msg: String) : RuntimeException(msg)
|
||||||
private fun checkOutput(command: String, result: Shell.Result, out: Boolean = result.out.isNotEmpty(),
|
fun checkOutput(command: String, result: Shell.Result, out: Boolean = result.out.isNotEmpty(),
|
||||||
err: Boolean = result.err.isNotEmpty()): String {
|
err: Boolean = result.err.isNotEmpty()): String {
|
||||||
val msg = StringBuilder("$command exited with ${result.code}")
|
val msg = StringBuilder("$command exited with ${result.code}")
|
||||||
if (out) result.out.forEach { msg.append("\n$it") }
|
if (out) result.out.forEach { msg.append("\n$it") }
|
||||||
if (err) result.err.forEach { msg.append("\nE $it") }
|
if (err) result.err.forEach { msg.append("\nE $it") }
|
||||||
@@ -101,22 +101,11 @@ class RootSession : AutoCloseable {
|
|||||||
}).exec()
|
}).exec()
|
||||||
}
|
}
|
||||||
fun exec(command: String) = checkOutput(command, execQuiet(command))
|
fun exec(command: String) = checkOutput(command, execQuiet(command))
|
||||||
fun execWithWait(command: String) {
|
|
||||||
val result = execQuiet(command)
|
|
||||||
val message = checkOutput(command, result, err = false)
|
|
||||||
if (result.err.isNotEmpty()) Timber.i(message)
|
|
||||||
}
|
|
||||||
fun execOutUnjoined(command: String): List<String> {
|
fun execOutUnjoined(command: String): List<String> {
|
||||||
val result = execQuiet(command)
|
val result = execQuiet(command)
|
||||||
checkOutput(command, result, false)
|
checkOutput(command, result, false)
|
||||||
return result.out
|
return result.out
|
||||||
}
|
}
|
||||||
fun execOutUnjoinedWithWait(command: String): List<String> {
|
|
||||||
val result = execQuiet(command)
|
|
||||||
val message = checkOutput(command, result, false, false)
|
|
||||||
if (result.err.isNotEmpty()) Timber.i(message)
|
|
||||||
return result.out
|
|
||||||
}
|
|
||||||
fun execOut(command: String): String = execOutUnjoined(command).joinToString("\n")
|
fun execOut(command: String): String = execOutUnjoined(command).joinToString("\n")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,7 +116,11 @@ class RootSession : AutoCloseable {
|
|||||||
|
|
||||||
fun exec(command: String, revert: String? = null, wait: Boolean = false) {
|
fun exec(command: String, revert: String? = null, wait: Boolean = false) {
|
||||||
if (revert != null) revertCommands.addFirst(revert) // add first just in case exec fails
|
if (revert != null) revertCommands.addFirst(revert) // add first just in case exec fails
|
||||||
if (wait) this@RootSession.execWithWait(command) else this@RootSession.exec(command)
|
if (wait) {
|
||||||
|
val result = this@RootSession.execQuiet(command)
|
||||||
|
val message = checkOutput(command, result, err = false)
|
||||||
|
if (result.err.isNotEmpty()) Timber.i(message)
|
||||||
|
} else this@RootSession.exec(command)
|
||||||
}
|
}
|
||||||
fun execQuiet(command: String) = this@RootSession.execQuiet(command)
|
fun execQuiet(command: String) = this@RootSession.execQuiet(command)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user