Make compatible with F-Droid (#42)
* Make compatible with F-Droid * Fix title bar empty
This commit is contained in:
@@ -4,7 +4,7 @@ import android.util.Log
|
||||
import be.mygod.vpnhotspot.R
|
||||
import be.mygod.vpnhotspot.util.thread
|
||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import timber.log.Timber
|
||||
import java.io.IOException
|
||||
import java.io.InterruptedIOException
|
||||
import java.util.concurrent.Executors
|
||||
@@ -25,25 +25,21 @@ abstract class IpMonitor : Runnable {
|
||||
val process = try {
|
||||
builder.start()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
Timber.d(e)
|
||||
return false
|
||||
}
|
||||
monitor = process
|
||||
val err = thread("${javaClass.simpleName}-error") {
|
||||
try {
|
||||
process.errorStream.bufferedReader().forEachLine {
|
||||
Crashlytics.log(Log.ERROR, javaClass.simpleName, it)
|
||||
}
|
||||
process.errorStream.bufferedReader().forEachLine { Timber.e(it) }
|
||||
} catch (_: InterruptedIOException) { } catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
Crashlytics.logException(e)
|
||||
Timber.w(e)
|
||||
}
|
||||
}
|
||||
try {
|
||||
process.inputStream.bufferedReader().forEachLine(this::processLine)
|
||||
} catch (_: InterruptedIOException) { } catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
Crashlytics.logException(e)
|
||||
Timber.w(e)
|
||||
}
|
||||
err.join()
|
||||
process.waitFor()
|
||||
@@ -56,8 +52,8 @@ abstract class IpMonitor : Runnable {
|
||||
// monitor may get rejected by SELinux
|
||||
if (handleProcess(ProcessBuilder("ip", "monitor", monitoredObject))) return@thread
|
||||
if (handleProcess(ProcessBuilder("su", "-c", "exec ip monitor $monitoredObject"))) return@thread
|
||||
Crashlytics.log(Log.WARN, javaClass.simpleName, "Failed to set up monitor, switching to polling")
|
||||
Crashlytics.logException(MonitorFailure())
|
||||
Timber.w("Failed to set up monitor, switching to polling")
|
||||
Timber.i(MonitorFailure())
|
||||
val pool = Executors.newScheduledThreadPool(1)
|
||||
pool.scheduleAtFixedRate(this, 1, 1, TimeUnit.SECONDS)
|
||||
this.pool = pool
|
||||
@@ -74,8 +70,8 @@ abstract class IpMonitor : Runnable {
|
||||
thread("${javaClass.simpleName}-flush-error") {
|
||||
val err = process.errorStream.bufferedReader().readText()
|
||||
if (err.isNotBlank()) {
|
||||
Crashlytics.log(Log.ERROR, javaClass.simpleName, err)
|
||||
Crashlytics.logException(FlushFailure())
|
||||
Timber.e(err)
|
||||
Timber.i(FlushFailure())
|
||||
SmartSnackbar.make(R.string.noisy_su_failure).show()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package be.mygod.vpnhotspot.net
|
||||
|
||||
import android.util.Log
|
||||
import be.mygod.vpnhotspot.util.parseNumericAddressNoThrow
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.net.InetAddress
|
||||
@@ -13,8 +12,6 @@ data class IpNeighbour(val ip: InetAddress, val dev: String, val lladdr: String,
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "IpNeighbour"
|
||||
|
||||
/**
|
||||
* Parser based on:
|
||||
* https://android.googlesource.com/platform/external/iproute2/+/ad0a6a2/ip/ipneigh.c#194
|
||||
@@ -28,7 +25,7 @@ data class IpNeighbour(val ip: InetAddress, val dev: String, val lladdr: String,
|
||||
fun parse(line: String): IpNeighbour? {
|
||||
val match = parser.matchEntire(line)
|
||||
if (match == null) {
|
||||
if (line.isNotEmpty()) Crashlytics.log(Log.WARN, TAG, line)
|
||||
if (line.isNotEmpty()) Timber.w(line)
|
||||
return null
|
||||
}
|
||||
val ip = parseNumericAddressNoThrow(match.groupValues[2]) ?: return null
|
||||
@@ -47,7 +44,7 @@ data class IpNeighbour(val ip: InetAddress, val dev: String, val lladdr: String,
|
||||
"FAILED" -> State.FAILED
|
||||
"NOARP" -> return null // skip
|
||||
else -> {
|
||||
Crashlytics.log(Log.WARN, TAG, "Unknown state encountered: ${match.groupValues[10]}")
|
||||
Timber.w("Unknown state encountered: ${match.groupValues[10]}")
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -73,8 +70,7 @@ data class IpNeighbour(val ip: InetAddress, val dev: String, val lladdr: String,
|
||||
.filter { it.size >= 6 && mac.matcher(it[ARP_HW_ADDRESS]).matches() }
|
||||
.toList()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
Crashlytics.logException(e)
|
||||
Timber.w(e)
|
||||
}
|
||||
return arpCache
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package be.mygod.vpnhotspot.net
|
||||
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import be.mygod.vpnhotspot.util.debugLog
|
||||
import be.mygod.vpnhotspot.debugLog
|
||||
import java.net.InetAddress
|
||||
|
||||
class IpNeighbourMonitor private constructor() : IpMonitor() {
|
||||
|
||||
@@ -10,12 +10,12 @@ import be.mygod.vpnhotspot.App.Companion.app
|
||||
import be.mygod.vpnhotspot.R
|
||||
import be.mygod.vpnhotspot.client.Client
|
||||
import be.mygod.vpnhotspot.client.ClientMonitorService
|
||||
import be.mygod.vpnhotspot.debugLog
|
||||
import be.mygod.vpnhotspot.util.RootSession
|
||||
import be.mygod.vpnhotspot.util.computeIfAbsentCompat
|
||||
import be.mygod.vpnhotspot.util.debugLog
|
||||
import be.mygod.vpnhotspot.util.stopAndUnbind
|
||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import timber.log.Timber
|
||||
import java.net.*
|
||||
|
||||
/**
|
||||
@@ -165,8 +165,7 @@ class Routing(private val owner: Context, val upstream: String?, private val dow
|
||||
try {
|
||||
subroutes.computeIfAbsentCompat(ip) { Subroute(ip, client) }
|
||||
} catch (e: Exception) {
|
||||
Crashlytics.logException(e)
|
||||
e.printStackTrace()
|
||||
Timber.w(e)
|
||||
SmartSnackbar.make(e.localizedMessage).show()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,10 @@ import android.net.ConnectivityManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.util.Log
|
||||
import androidx.annotation.RequiresApi
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import com.android.dx.stock.ProxyBuilder
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* Heavily based on:
|
||||
@@ -32,8 +31,6 @@ object TetheringManager {
|
||||
fun onTetheringFailed() { }
|
||||
}
|
||||
|
||||
private const val TAG = "TetheringManager"
|
||||
|
||||
/**
|
||||
* This is a sticky broadcast since almost forever.
|
||||
*
|
||||
@@ -121,7 +118,7 @@ object TetheringManager {
|
||||
val proxy = ProxyBuilder.forClass(classOnStartTetheringCallback)
|
||||
.dexCache(app.cacheDir)
|
||||
.handler { proxy, method, args ->
|
||||
if (args.isNotEmpty()) Crashlytics.log(Log.WARN, TAG, "Unexpected args for ${method.name}: $args")
|
||||
if (args.isNotEmpty()) Timber.w("Unexpected args for ${method.name}: $args")
|
||||
when (method.name) {
|
||||
"onTetheringStarted" -> {
|
||||
callback.onTetheringStarted()
|
||||
@@ -132,7 +129,7 @@ object TetheringManager {
|
||||
null
|
||||
}
|
||||
else -> {
|
||||
Crashlytics.log(Log.WARN, TAG, "Unexpected method, calling super: $method")
|
||||
Timber.w("Unexpected method, calling super: $method")
|
||||
ProxyBuilder.callSuper(proxy, method, args)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package be.mygod.vpnhotspot.net
|
||||
|
||||
import android.os.SystemClock
|
||||
import android.util.Log
|
||||
import android.util.LongSparseArray
|
||||
import be.mygod.vpnhotspot.room.AppDatabase
|
||||
import be.mygod.vpnhotspot.room.TrafficRecord
|
||||
@@ -10,7 +9,7 @@ import be.mygod.vpnhotspot.room.macToLong
|
||||
import be.mygod.vpnhotspot.util.Event2
|
||||
import be.mygod.vpnhotspot.util.RootSession
|
||||
import be.mygod.vpnhotspot.util.parseNumericAddress
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import timber.log.Timber
|
||||
import java.net.InetAddress
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@@ -112,9 +111,8 @@ object TrafficRecorder {
|
||||
else -> check(false)
|
||||
}
|
||||
} catch (e: RuntimeException) {
|
||||
Crashlytics.log(Log.WARN, TAG, line)
|
||||
e.printStackTrace()
|
||||
Crashlytics.logException(e)
|
||||
Timber.w(line)
|
||||
Timber.w(e)
|
||||
}
|
||||
}
|
||||
for ((_, record) in records) if (record.id == null) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import android.net.Network
|
||||
import android.net.NetworkCapabilities
|
||||
import android.net.NetworkRequest
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import be.mygod.vpnhotspot.util.debugLog
|
||||
import be.mygod.vpnhotspot.debugLog
|
||||
|
||||
object VpnMonitor : UpstreamMonitor() {
|
||||
private const val TAG = "VpnMonitor"
|
||||
|
||||
@@ -4,10 +4,9 @@ import android.net.wifi.WifiConfiguration
|
||||
import android.os.Build
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import android.util.Log
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import be.mygod.vpnhotspot.util.RootSession
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
@@ -16,7 +15,6 @@ class P2pSupplicantConfiguration(private val initContent: String? = null) : Parc
|
||||
override fun createFromParcel(parcel: Parcel) = P2pSupplicantConfiguration(parcel.readString())
|
||||
override fun newArray(size: Int): Array<P2pSupplicantConfiguration?> = arrayOfNulls(size)
|
||||
|
||||
private const val TAG = "P2pSupplicationConf"
|
||||
/**
|
||||
* Format for ssid is much more complicated, therefore we are only trying to find the line and rely on
|
||||
* Android's results instead.
|
||||
@@ -55,9 +53,8 @@ class P2pSupplicantConfiguration(private val initContent: String? = null) : Parc
|
||||
} catch (e: NoSuchElementException) {
|
||||
null
|
||||
} catch (e: RuntimeException) {
|
||||
if (contentDelegate.isInitialized()) Crashlytics.log(Log.WARN, TAG, content)
|
||||
e.printStackTrace()
|
||||
Crashlytics.logException(e)
|
||||
if (contentDelegate.isInitialized()) Timber.w(content)
|
||||
Timber.w(e)
|
||||
null
|
||||
}
|
||||
}
|
||||
@@ -82,9 +79,9 @@ class P2pSupplicantConfiguration(private val initContent: String? = null) : Parc
|
||||
})
|
||||
}
|
||||
if (ssidFound != 1 || pskFound != 1) {
|
||||
Crashlytics.log(Log.WARN, TAG, "Invalid conf ($ssidFound, $pskFound): $content")
|
||||
Timber.w("Invalid conf ($ssidFound, $pskFound): $content")
|
||||
if (ssidFound == 0 || pskFound == 0) throw InvalidConfigurationError()
|
||||
else Crashlytics.logException(InvalidConfigurationError())
|
||||
else Timber.i(InvalidConfigurationError())
|
||||
}
|
||||
// pkill not available on Lollipop. Source: https://android.googlesource.com/platform/system/core/+/master/shell_and_utilities/README.md
|
||||
RootSession.use {
|
||||
|
||||
@@ -4,14 +4,12 @@ import android.annotation.SuppressLint
|
||||
import android.net.wifi.WpsInfo
|
||||
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 timber.log.Timber
|
||||
import java.lang.reflect.Proxy
|
||||
import java.util.regex.Pattern
|
||||
|
||||
object WifiP2pManagerHelper {
|
||||
private const val TAG = "WifiP2pManagerHelper"
|
||||
const val UNSUPPORTED = -2
|
||||
|
||||
/**
|
||||
@@ -41,8 +39,7 @@ object WifiP2pManagerHelper {
|
||||
try {
|
||||
setWifiP2pChannels.invoke(this, c, lc, oc, listener)
|
||||
} catch (e: NoSuchMethodException) {
|
||||
e.printStackTrace()
|
||||
Crashlytics.logException(e)
|
||||
Timber.w(e)
|
||||
listener.onFailure(UNSUPPORTED)
|
||||
}
|
||||
}
|
||||
@@ -60,8 +57,7 @@ object WifiP2pManagerHelper {
|
||||
try {
|
||||
startWps.invoke(this, c, wps, listener)
|
||||
} catch (e: NoSuchMethodException) {
|
||||
e.printStackTrace()
|
||||
Crashlytics.logException(e)
|
||||
Timber.w(e)
|
||||
listener.onFailure(UNSUPPORTED)
|
||||
}
|
||||
}
|
||||
@@ -80,8 +76,7 @@ object WifiP2pManagerHelper {
|
||||
try {
|
||||
deletePersistentGroup.invoke(this, c, netId, listener)
|
||||
} catch (e: NoSuchMethodException) {
|
||||
e.printStackTrace()
|
||||
Crashlytics.logException(e)
|
||||
Timber.w(e)
|
||||
listener.onFailure(UNSUPPORTED)
|
||||
}
|
||||
}
|
||||
@@ -107,11 +102,11 @@ object WifiP2pManagerHelper {
|
||||
val proxy = Proxy.newProxyInstance(interfacePersistentGroupInfoListener.classLoader,
|
||||
arrayOf(interfacePersistentGroupInfoListener)) { proxy, method, args ->
|
||||
if (method.name == "onPersistentGroupInfoAvailable") {
|
||||
if (args.size != 1) Crashlytics.log(Log.WARN, TAG, "Unexpected args: $args")
|
||||
if (args.size != 1) Timber.w("Unexpected args: $args")
|
||||
listener(getGroupList.invoke(args[0]) as Collection<WifiP2pGroup>)
|
||||
null
|
||||
} else {
|
||||
Crashlytics.log(Log.WARN, TAG, "Unexpected method, calling super: $method")
|
||||
Timber.w("Unexpected method, calling super: $method")
|
||||
ProxyBuilder.callSuper(proxy, method, args)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user