From 66185ad08e471ac94f845cb4a7d0b4d0e37ad71c Mon Sep 17 00:00:00 2001 From: casey langen Date: Tue, 24 Dec 2019 19:00:25 -0800 Subject: [PATCH] Shifted code around to hopefully fix #296 --- .../remote/service/system/SystemService.kt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/service/system/SystemService.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/service/system/SystemService.kt index 4b80a95f8..54a472120 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/service/system/SystemService.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/service/system/SystemService.kt @@ -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(HEADSET_DOUBLE_PAUSE_HACK_DEBOUNCE_MS) { override fun onDebounced(last: Void?) {