diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt index 2530b106..6236676c 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt @@ -26,6 +26,7 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService() { fun stop() = reservation?.close() } + private class StartFailure(message: String) : RuntimeException(message) private val binder = Binder() private var reservation: WifiManager.LocalOnlyHotspotReservation? = null @@ -76,7 +77,7 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService() { } override fun onFailed(reason: Int) { - Toast.makeText(this@LocalOnlyHotspotService, getString(R.string.tethering_temp_hotspot_failure, + val message = getString(R.string.tethering_temp_hotspot_failure, when (reason) { WifiManager.LocalOnlyHotspotCallback.ERROR_NO_CHANNEL -> getString(R.string.tethering_temp_hotspot_failure_no_channel) @@ -87,7 +88,9 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService() { WifiManager.LocalOnlyHotspotCallback.ERROR_TETHERING_DISALLOWED -> getString(R.string.tethering_temp_hotspot_failure_tethering_disallowed) else -> getString(R.string.failure_reason_unknown, reason) - }), Toast.LENGTH_SHORT).show() + }) + Toast.makeText(this@LocalOnlyHotspotService, message, Toast.LENGTH_SHORT).show() + Crashlytics.logException(StartFailure(message)) } }, app.handler) } catch (e: IllegalStateException) { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt index a73ce391..e555b901 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt @@ -33,6 +33,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere enum class Status { IDLE, STARTING, ACTIVE } + private class Failure(message: String) : RuntimeException(message) inner class Binder : android.os.Binder() { val service get() = this@RepeaterService @@ -115,13 +116,17 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere binder.statusChanged() } - private fun formatReason(@StringRes resId: Int, reason: Int) = getString(resId, when (reason) { - WifiP2pManager.ERROR -> getString(R.string.repeater_failure_reason_error) - WifiP2pManager.P2P_UNSUPPORTED -> getString(R.string.repeater_failure_reason_p2p_unsupported) - WifiP2pManager.BUSY -> getString(R.string.repeater_failure_reason_busy) - WifiP2pManager.NO_SERVICE_REQUESTS -> getString(R.string.repeater_failure_reason_no_service_requests) - else -> getString(R.string.failure_reason_unknown, reason) - }) + private fun formatReason(@StringRes resId: Int, reason: Int): String? { + val result = getString(resId, when (reason) { + WifiP2pManager.ERROR -> getString(R.string.repeater_failure_reason_error) + WifiP2pManager.P2P_UNSUPPORTED -> getString(R.string.repeater_failure_reason_p2p_unsupported) + WifiP2pManager.BUSY -> getString(R.string.repeater_failure_reason_busy) + WifiP2pManager.NO_SERVICE_REQUESTS -> getString(R.string.repeater_failure_reason_no_service_requests) + else -> getString(R.string.failure_reason_unknown, reason) + }) + Crashlytics.logException(Failure(result)) + return result + } override fun onCreate() { super.onCreate() @@ -147,8 +152,11 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere } }) } catch (e: InvocationTargetException) { - if (oc != 0) - Toast.makeText(this, getString(R.string.repeater_set_oc_failure, e.message), Toast.LENGTH_SHORT).show() + if (oc != 0) { + val message = getString(R.string.repeater_set_oc_failure, e.message) + Toast.makeText(this, message, Toast.LENGTH_SHORT).show() + Crashlytics.logException(Failure(message)) + } e.printStackTrace() Crashlytics.logException(e) }