Migrate to open source firebase-crashlytics

This commit is contained in:
Mygod
2020-01-24 22:22:48 +08:00
parent b55ad234ac
commit 3cee5a4782
18 changed files with 67 additions and 125 deletions

View File

@@ -3,7 +3,6 @@ package be.mygod.vpnhotspot.net.monitor
import android.system.ErrnoException
import android.system.OsConstants
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.DebugHelper
import be.mygod.vpnhotspot.R
import be.mygod.vpnhotspot.util.RootSession
import be.mygod.vpnhotspot.widget.SmartSnackbar
@@ -64,7 +63,7 @@ abstract class IpMonitor : Runnable {
}
err.join()
process.waitFor()
DebugHelper.log("IpMonitor", "Monitor process exited with ${process.exitValue()}")
Timber.d("Monitor process exited with ${process.exitValue()}")
}
init {
@@ -78,7 +77,7 @@ abstract class IpMonitor : Runnable {
}
handleProcess(ProcessBuilder("su", "-c", "exec ip monitor $monitoredObject"))
if (destroyed) return@thread
DebugHelper.logEvent("ip_monitor_failure")
app.logEvent("ip_monitor_failure")
}
val pool = Executors.newScheduledThreadPool(1)
pool.scheduleAtFixedRate(this, 1, 1, TimeUnit.SECONDS)
@@ -113,7 +112,7 @@ abstract class IpMonitor : Runnable {
if (currentMode != Mode.PollRoot) try {
return poll()
} catch (e: IOException) {
DebugHelper.logEvent("ip_poll_failure")
app.logEvent("ip_poll_failure")
Timber.d(e)
}
try {
@@ -125,7 +124,7 @@ abstract class IpMonitor : Runnable {
processLines(result.out.asSequence())
}
} catch (e: RuntimeException) {
DebugHelper.logEvent("ip_su_poll_failure")
app.logEvent("ip_su_poll_failure")
Timber.w(e)
}
}

View File

@@ -2,7 +2,6 @@ package be.mygod.vpnhotspot.net.monitor
import android.util.LongSparseArray
import androidx.core.os.postDelayed
import be.mygod.vpnhotspot.DebugHelper
import be.mygod.vpnhotspot.net.Routing.Companion.IPTABLES
import be.mygod.vpnhotspot.room.AppDatabase
import be.mygod.vpnhotspot.room.TrafficRecord
@@ -15,7 +14,6 @@ import java.net.InetAddress
import java.util.concurrent.TimeUnit
object TrafficRecorder {
private const val TAG = "TrafficRecorder"
private const val ANYWHERE = "0.0.0.0/0"
private var scheduled = false
@@ -27,14 +25,14 @@ object TrafficRecorder {
val record = TrafficRecord(mac = mac, ip = ip, downstream = downstream)
AppDatabase.instance.trafficRecordDao.insert(record)
synchronized(this) {
DebugHelper.log(TAG, "Registering $ip%$downstream")
Timber.d("Registering $ip%$downstream")
check(records.putIfAbsent(Pair(ip, downstream), record) == null)
scheduleUpdateLocked()
}
}
fun unregister(ip: InetAddress, downstream: String) = synchronized(this) {
update() // flush stats before removing
DebugHelper.log(TAG, "Unregistering $ip%$downstream")
Timber.d("Unregistering $ip%$downstream")
if (records.remove(Pair(ip, downstream)) == null) Timber.w("Failed to find traffic record for $ip%$downstream.")
}
@@ -142,7 +140,7 @@ object TrafficRecorder {
fun clean() = synchronized(this) {
update()
unscheduleUpdateLocked()
DebugHelper.log(TAG, "Cleaning records")
Timber.d("Cleaning records")
records.clear()
}

View File

@@ -2,12 +2,9 @@ package be.mygod.vpnhotspot.net.monitor
import android.net.*
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.DebugHelper
import timber.log.Timber
object VpnMonitor : UpstreamMonitor() {
private const val TAG = "VpnMonitor"
private val request = NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_VPN)
.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)
@@ -66,7 +63,7 @@ object VpnMonitor : UpstreamMonitor() {
if (available.isNotEmpty()) {
val next = available.entries.first()
currentNetwork = next.key
DebugHelper.log(TAG, "Switching to ${next.value.interfaceName} as VPN interface")
Timber.d("Switching to ${next.value.interfaceName} as VPN interface")
callbacks.forEach { it.onAvailable(next.value.interfaceName!!, next.value) }
} else currentNetwork = null
}

View File

@@ -4,7 +4,7 @@ import android.annotation.SuppressLint
import android.net.wifi.WpsInfo
import android.net.wifi.p2p.WifiP2pGroup
import android.net.wifi.p2p.WifiP2pManager
import be.mygod.vpnhotspot.DebugHelper
import be.mygod.vpnhotspot.App.Companion.app
import com.android.dx.stock.ProxyBuilder
import timber.log.Timber
import java.lang.reflect.Proxy
@@ -30,7 +30,7 @@ object WifiP2pManagerHelper {
try {
setWifiP2pChannels.invoke(this, c, lc, oc, listener)
} catch (_: NoSuchMethodException) {
DebugHelper.logEvent("NoSuchMethod_setWifiP2pChannels")
app.logEvent("NoSuchMethod_setWifiP2pChannels")
listener.onFailure(UNSUPPORTED)
}
}
@@ -46,7 +46,7 @@ object WifiP2pManagerHelper {
WifiP2pManager::class.java.getDeclaredMethod("startWps",
WifiP2pManager.Channel::class.java, WpsInfo::class.java, WifiP2pManager.ActionListener::class.java)
} catch (_: NoSuchMethodException) {
DebugHelper.logEvent("NoSuchMethod_startWps")
app.logEvent("NoSuchMethod_startWps")
null
}
}
@@ -69,7 +69,7 @@ object WifiP2pManagerHelper {
try {
deletePersistentGroup.invoke(this, c, netId, listener)
} catch (_: NoSuchMethodException) {
DebugHelper.logEvent("NoSuchMethod_deletePersistentGroup")
app.logEvent("NoSuchMethod_deletePersistentGroup")
listener.onFailure(UNSUPPORTED)
}
}

View File

@@ -3,7 +3,6 @@ package be.mygod.vpnhotspot.net.wifi.configuration
import android.net.wifi.p2p.WifiP2pGroup
import android.os.Build
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.DebugHelper
import be.mygod.vpnhotspot.RepeaterService
import be.mygod.vpnhotspot.util.RootSession
import java.io.File
@@ -109,9 +108,9 @@ class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress:
}
Triple(result, target!!, shell.err.isNotEmpty())
} catch (e: RuntimeException) {
DebugHelper.setString(TAG, parser.lines.joinToString("\n"))
DebugHelper.setString("$TAG.ownerAddress", ownerAddress)
DebugHelper.setString("$TAG.p2pGroup", group.toString())
app.crashlytics.setCustomKey(TAG, parser.lines.joinToString("\n"))
app.crashlytics.setCustomKey("$TAG.ownerAddress", ownerAddress.toString())
app.crashlytics.setCustomKey("$TAG.p2pGroup", group.toString())
throw e
}
}