Add more logging
This commit is contained in:
@@ -4,12 +4,15 @@ import android.util.Log
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import be.mygod.vpnhotspot.R
|
||||
import be.mygod.vpnhotspot.util.thread
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import java.io.InterruptedIOException
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.ScheduledExecutorService
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
abstract class IpMonitor : Runnable {
|
||||
private class MonitorFailure : RuntimeException()
|
||||
private class FlushFailure : RuntimeException()
|
||||
protected abstract val monitoredObject: String
|
||||
protected abstract fun processLine(line: String)
|
||||
protected abstract fun processLines(lines: Sequence<String>)
|
||||
@@ -27,14 +30,17 @@ abstract class IpMonitor : Runnable {
|
||||
this.monitor = monitor
|
||||
thread("${javaClass.simpleName}-error") {
|
||||
try {
|
||||
monitor.errorStream.bufferedReader().forEachLine { Log.e(javaClass.simpleName, it) }
|
||||
monitor.errorStream.bufferedReader().forEachLine {
|
||||
Crashlytics.log(Log.ERROR, javaClass.simpleName, it)
|
||||
}
|
||||
} catch (_: InterruptedIOException) { }
|
||||
}
|
||||
try {
|
||||
monitor.inputStream.bufferedReader().forEachLine(this::processLine)
|
||||
monitor.waitFor()
|
||||
if (monitor.exitValue() == 0) return@thread
|
||||
Log.w(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())
|
||||
val pool = Executors.newScheduledThreadPool(1)
|
||||
pool.scheduleAtFixedRate(this, 1, 1, TimeUnit.SECONDS)
|
||||
this.pool = pool
|
||||
@@ -52,7 +58,8 @@ abstract class IpMonitor : Runnable {
|
||||
thread("${javaClass.simpleName}-flush-error") {
|
||||
val err = process.errorStream.bufferedReader().readText()
|
||||
if (err.isNotBlank()) {
|
||||
Log.e(javaClass.simpleName, err)
|
||||
Crashlytics.log(Log.ERROR, javaClass.simpleName, err)
|
||||
Crashlytics.logException(FlushFailure())
|
||||
app.toast(R.string.noisy_su_failure)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package be.mygod.vpnhotspot.net
|
||||
|
||||
import android.util.Log
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
@@ -25,7 +26,7 @@ data class IpNeighbour(val ip: String, val dev: String, val lladdr: String, val
|
||||
fun parse(line: String): IpNeighbour? {
|
||||
val match = parser.matchEntire(line)
|
||||
if (match == null) {
|
||||
if (line.isNotEmpty()) Log.w(TAG, line)
|
||||
if (line.isNotEmpty()) Crashlytics.log(Log.WARN, TAG, line)
|
||||
return null
|
||||
}
|
||||
val ip = match.groupValues[2]
|
||||
@@ -43,7 +44,7 @@ data class IpNeighbour(val ip: String, val dev: String, val lladdr: String, val
|
||||
"FAILED" -> State.FAILED
|
||||
"NOARP" -> return null // skip
|
||||
else -> {
|
||||
Log.w(TAG, "Unknown state encountered: ${match.groupValues[10]}")
|
||||
Crashlytics.log(Log.WARN, TAG, "Unknown state encountered: ${match.groupValues[10]}")
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -70,6 +71,7 @@ data class IpNeighbour(val ip: String, val dev: String, val lladdr: String, val
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
Crashlytics.logException(e)
|
||||
}
|
||||
return arpCache
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.support.annotation.RequiresApi
|
||||
import android.util.Log
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import com.android.dx.stock.ProxyBuilder
|
||||
import com.crashlytics.android.Crashlytics
|
||||
|
||||
/**
|
||||
* Heavily based on:
|
||||
@@ -91,7 +92,7 @@ object TetheringManager {
|
||||
val proxy = ProxyBuilder.forClass(classOnStartTetheringCallback)
|
||||
.dexCache(app.cacheDir)
|
||||
.handler { proxy, method, args ->
|
||||
if (args.isNotEmpty()) Log.w(TAG, "Unexpected args for ${method.name}: $args")
|
||||
if (args.isNotEmpty()) Crashlytics.log(Log.WARN, TAG, "Unexpected args for ${method.name}: $args")
|
||||
when (method.name) {
|
||||
"onTetheringStarted" -> {
|
||||
callback.onTetheringStarted()
|
||||
@@ -102,7 +103,7 @@ object TetheringManager {
|
||||
null
|
||||
}
|
||||
else -> {
|
||||
Log.w(TAG, "Unexpected method, calling super: $method")
|
||||
Crashlytics.log(Log.WARN, TAG, "Unexpected method, calling super: $method")
|
||||
ProxyBuilder.callSuper(proxy, method, args)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.widget.Toast
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import be.mygod.vpnhotspot.util.loggerSu
|
||||
import be.mygod.vpnhotspot.util.noisySu
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import java.io.File
|
||||
|
||||
class P2pSupplicantConfiguration {
|
||||
@@ -34,8 +35,9 @@ class P2pSupplicantConfiguration {
|
||||
check(result.length in 8..63)
|
||||
result
|
||||
} catch (e: RuntimeException) {
|
||||
Log.w(TAG, content)
|
||||
Crashlytics.log(Log.WARN, TAG, content)
|
||||
e.printStackTrace()
|
||||
Crashlytics.logException(e)
|
||||
Toast.makeText(app, e.message, Toast.LENGTH_LONG).show()
|
||||
null
|
||||
}
|
||||
@@ -61,7 +63,9 @@ class P2pSupplicantConfiguration {
|
||||
else -> line // do nothing
|
||||
})
|
||||
}
|
||||
if (ssidFound != 1 || pskFound != 1) Log.w(TAG, "Invalid conf ($ssidFound, $pskFound): $content")
|
||||
if (ssidFound != 1 || pskFound != 1) {
|
||||
Crashlytics.log(Log.WARN, TAG, "Invalid conf ($ssidFound, $pskFound): $content")
|
||||
}
|
||||
if (ssidFound == 0 || pskFound == 0) return false
|
||||
// pkill not available on Lollipop. Source: https://android.googlesource.com/platform/system/core/+/master/shell_and_utilities/README.md
|
||||
return noisySu("cat ${tempFile.absolutePath} > /data/misc/wifi/p2p_supplicant.conf",
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.net.wifi.p2p.WifiP2pGroup
|
||||
import android.net.wifi.p2p.WifiP2pManager
|
||||
import android.util.Log
|
||||
import com.android.dx.stock.ProxyBuilder
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import java.lang.reflect.Proxy
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@@ -88,11 +89,11 @@ object WifiP2pManagerHelper {
|
||||
val proxy = Proxy.newProxyInstance(interfacePersistentGroupInfoListener.classLoader,
|
||||
arrayOf(interfacePersistentGroupInfoListener), { proxy, method, args ->
|
||||
if (method.name == "onPersistentGroupInfoAvailable") {
|
||||
if (args.size != 1) Log.w(TAG, "Unexpected args: $args")
|
||||
if (args.size != 1) Crashlytics.log(Log.WARN, TAG, "Unexpected args: $args")
|
||||
listener(getGroupList.invoke(args[0]) as Collection<WifiP2pGroup>)
|
||||
null
|
||||
} else {
|
||||
Log.w(TAG, "Unexpected method, calling super: $method")
|
||||
Crashlytics.log(Log.WARN, TAG, "Unexpected method, calling super: $method")
|
||||
ProxyBuilder.callSuper(proxy, method, args)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user