From f897368c6158392776ba7a2b676ad7febda8b6af Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 11 Jun 2018 20:22:39 +0800 Subject: [PATCH] Fix more ANR caused by LOHService --- .../mygod/vpnhotspot/LocalOnlyHotspotService.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt index 5239670c..6931b9fe 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt @@ -90,22 +90,27 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService() { else -> getString(R.string.failure_reason_unknown, reason) }) Toast.makeText(this@LocalOnlyHotspotService, message, Toast.LENGTH_SHORT).show() - Crashlytics.logException(StartFailure(message)) - updateNotification() - ServiceNotification.stopForeground(this@LocalOnlyHotspotService) + startFailure(StartFailure(message)) } }, app.handler) } catch (e: IllegalStateException) { e.printStackTrace() - Crashlytics.logException(e) + startFailure(e) } catch (e: SecurityException) { Toast.makeText(this, e.message, Toast.LENGTH_LONG).show() e.printStackTrace() - Crashlytics.logException(e) + startFailure(e) } return START_STICKY } + private fun startFailure(e: Exception) { + Crashlytics.logException(e) + updateNotification() + ServiceNotification.stopForeground(this@LocalOnlyHotspotService) + stopSelf() + } + override fun onDestroy() { unregisterReceiver() super.onDestroy()