Fix crashes on root missing
This commit is contained in:
@@ -106,9 +106,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
|||||||
val conf = P2pSupplicantConfiguration()
|
val conf = P2pSupplicantConfiguration()
|
||||||
wifi.SSID = ssid
|
wifi.SSID = ssid
|
||||||
wifi.preSharedKey = group.passphrase
|
wifi.preSharedKey = group.passphrase
|
||||||
if (wifi.preSharedKey == null) {
|
if (wifi.preSharedKey == null) wifi.preSharedKey = conf.readPsk()
|
||||||
wifi.preSharedKey = conf.readPsk { SmartSnackbar.make(it.message.toString()).show() }
|
|
||||||
}
|
|
||||||
if (wifi.preSharedKey != null) {
|
if (wifi.preSharedKey != null) {
|
||||||
WifiP2pDialogFragment().apply {
|
WifiP2pDialogFragment().apply {
|
||||||
arguments = bundleOf(Pair(WifiP2pDialogFragment.KEY_CONFIGURATION, wifi),
|
arguments = bundleOf(Pair(WifiP2pDialogFragment.KEY_CONFIGURATION, wifi),
|
||||||
|
|||||||
@@ -21,7 +21,13 @@ abstract class IpMonitor : Runnable {
|
|||||||
private var monitor: Process? = null
|
private var monitor: Process? = null
|
||||||
private var pool: ScheduledExecutorService? = null
|
private var pool: ScheduledExecutorService? = null
|
||||||
|
|
||||||
private fun handleProcess(process: Process): Int {
|
private fun handleProcess(builder: ProcessBuilder): Int {
|
||||||
|
val process = try {
|
||||||
|
builder.start()
|
||||||
|
} catch (e: IOException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
return -1
|
||||||
|
}
|
||||||
val err = thread("${javaClass.simpleName}-error") {
|
val err = thread("${javaClass.simpleName}-error") {
|
||||||
try {
|
try {
|
||||||
process.errorStream.bufferedReader().forEachLine {
|
process.errorStream.bufferedReader().forEachLine {
|
||||||
@@ -46,9 +52,8 @@ abstract class IpMonitor : Runnable {
|
|||||||
init {
|
init {
|
||||||
thread("${javaClass.simpleName}-input") {
|
thread("${javaClass.simpleName}-input") {
|
||||||
// monitor may get rejected by SELinux
|
// monitor may get rejected by SELinux
|
||||||
if (handleProcess(ProcessBuilder("ip", "monitor", monitoredObject).start()) == 0) return@thread
|
if (handleProcess(ProcessBuilder("ip", "monitor", monitoredObject)) == 0) return@thread
|
||||||
if (handleProcess(ProcessBuilder("su", "-c", "exec ip monitor $monitoredObject").start()) == 0)
|
if (handleProcess(ProcessBuilder("su", "-c", "exec ip monitor $monitoredObject")) == 0) return@thread
|
||||||
return@thread
|
|
||||||
Crashlytics.log(Log.WARN, javaClass.simpleName, "Failed to set up monitor, switching to polling")
|
Crashlytics.log(Log.WARN, javaClass.simpleName, "Failed to set up monitor, switching to polling")
|
||||||
Crashlytics.logException(MonitorFailure())
|
Crashlytics.logException(MonitorFailure())
|
||||||
val pool = Executors.newScheduledThreadPool(1)
|
val pool = Executors.newScheduledThreadPool(1)
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class P2pSupplicantConfiguration(private val initContent: String? = null) : Parc
|
|||||||
private val contentDelegate = lazy { initContent ?: RootSession.use { it.execOut("cat $confPath") } }
|
private val contentDelegate = lazy { initContent ?: RootSession.use { it.execOut("cat $confPath") } }
|
||||||
private val content by contentDelegate
|
private val content by contentDelegate
|
||||||
|
|
||||||
fun readPsk(handler: ((RuntimeException) -> Unit)? = null): String? {
|
fun readPsk(): String? {
|
||||||
return try {
|
return try {
|
||||||
val match = pskParser.findAll(content).single()
|
val match = pskParser.findAll(content).single()
|
||||||
if (match.groups[2] == null && match.groups[3] == null) "" else {
|
if (match.groups[2] == null && match.groups[3] == null) "" else {
|
||||||
@@ -53,13 +53,11 @@ class P2pSupplicantConfiguration(private val initContent: String? = null) : Parc
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
} catch (e: NoSuchElementException) {
|
} catch (e: NoSuchElementException) {
|
||||||
handler?.invoke(e)
|
|
||||||
null
|
null
|
||||||
} catch (e: RuntimeException) {
|
} catch (e: RuntimeException) {
|
||||||
Crashlytics.log(Log.WARN, TAG, content)
|
if (contentDelegate.isInitialized()) Crashlytics.log(Log.WARN, TAG, content)
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
Crashlytics.logException(e)
|
Crashlytics.logException(e)
|
||||||
handler?.invoke(e)
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user