Fix more ANR caused by LOHService

This commit is contained in:
Mygod
2018-06-11 20:22:39 +08:00
parent 5e792b40e7
commit f897368c61

View File

@@ -90,22 +90,27 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService() {
else -> getString(R.string.failure_reason_unknown, reason) else -> getString(R.string.failure_reason_unknown, reason)
}) })
Toast.makeText(this@LocalOnlyHotspotService, message, Toast.LENGTH_SHORT).show() Toast.makeText(this@LocalOnlyHotspotService, message, Toast.LENGTH_SHORT).show()
Crashlytics.logException(StartFailure(message)) startFailure(StartFailure(message))
updateNotification()
ServiceNotification.stopForeground(this@LocalOnlyHotspotService)
} }
}, app.handler) }, app.handler)
} catch (e: IllegalStateException) { } catch (e: IllegalStateException) {
e.printStackTrace() e.printStackTrace()
Crashlytics.logException(e) startFailure(e)
} catch (e: SecurityException) { } catch (e: SecurityException) {
Toast.makeText(this, e.message, Toast.LENGTH_LONG).show() Toast.makeText(this, e.message, Toast.LENGTH_LONG).show()
e.printStackTrace() e.printStackTrace()
Crashlytics.logException(e) startFailure(e)
} }
return START_STICKY return START_STICKY
} }
private fun startFailure(e: Exception) {
Crashlytics.logException(e)
updateNotification()
ServiceNotification.stopForeground(this@LocalOnlyHotspotService)
stopSelf()
}
override fun onDestroy() { override fun onDestroy() {
unregisterReceiver() unregisterReceiver()
super.onDestroy() super.onDestroy()