Skip to content

Commit

Permalink
don't unbind NotificationListener on the first disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
crc-32 committed Jun 20, 2024
1 parent 89249cb commit 14b2f45
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
/build/
android/key.properties
android/key.jks
android/.kotlin/metadata

# Web related
lib/generated_plugin_registrant.dart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ import io.rebble.libpebblecommon.packets.blobdb.BlobResponse
import io.rebble.libpebblecommon.packets.blobdb.TimelineItem
import io.rebble.libpebblecommon.services.notification.NotificationService
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.*
import timber.log.Timber

class NotificationListener : NotificationListenerService() {
Expand Down Expand Up @@ -196,7 +193,7 @@ class NotificationListener : NotificationListenerService() {
// ServiceLifecycleControl to starts up back up when watch reconnects.

coroutineScope.launch(Dispatchers.Main.immediate) {
connectionLooper.connectionState.collect {
connectionLooper.connectionState.drop(1).collect {
if (it is ConnectionState.Disconnected || it is ConnectionState.RecoveryMode) {
Timber.d("Connection state is $it, unbinding listener")
requestUnbind()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class ServiceLifecycleControl @Inject constructor(
context.stopService(serviceIntent)
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
shouldServiceBeRunning &&
if (shouldServiceBeRunning &&
context.hasNotificationAccessPermission() && it !is ConnectionState.RecoveryMode) {
Timber.d("Requesting notifications rebind")
NotificationListenerService.requestRebind(
NotificationListener.getComponentName(context)
)
Expand Down

0 comments on commit 14b2f45

Please sign in to comment.