Shifted code around to hopefully fix #296

This commit is contained in:
casey langen 2019-12-24 19:00:25 -08:00
parent a6df6c9c21
commit 66185ad08e

View File

@ -65,6 +65,8 @@ class SystemService : Service() {
private val sessionData = SessionMetadata()
override fun onCreate() {
Log.d(TAG, "onCreate")
state = State.Sleeping
super.onCreate()
@ -79,9 +81,8 @@ class SystemService : Service() {
channel.setSound(null, null)
channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
val nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
nm.deleteNotificationChannel(NOTIFICATION_CHANNEL)
nm.createNotificationChannel(channel)
notificationManager.deleteNotificationChannel(NOTIFICATION_CHANNEL)
notificationManager.createNotificationChannel(channel)
}
prefs = getSharedPreferences(Prefs.NAME, Context.MODE_PRIVATE)
@ -92,13 +93,20 @@ class SystemService : Service() {
}
override fun onDestroy() {
Log.d(TAG, "onDestroy")
state = State.Dead
super.onDestroy()
releaseWakeLock()
unregisterReceivers()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationManager.deleteNotificationChannel(NOTIFICATION_CHANNEL)
}
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Log.d(TAG, "onStartCommand")
if (intent != null && intent.action != null) {
when (intent.action) {
ACTION_WAKE_UP -> wakeupNow()
@ -430,6 +438,9 @@ class SystemService : Service() {
}
}
private val notificationManager: NotificationManager
get() = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
private val headsetDoublePauseHackDebouncer =
object: Debouncer<Void>(HEADSET_DOUBLE_PAUSE_HACK_DEBOUNCE_MS) {
override fun onDebounced(last: Void?) {