diff --git a/.gitignore b/.gitignore index b55bcba7..d6b4cf21 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ /build/ android/key.properties android/key.jks +android/.kotlin/metadata # Web related lib/generated_plugin_registrant.dart diff --git a/android/app/src/main/kotlin/io/rebble/cobble/notifications/NotificationListener.kt b/android/app/src/main/kotlin/io/rebble/cobble/notifications/NotificationListener.kt index d29a01e0..03175607 100644 --- a/android/app/src/main/kotlin/io/rebble/cobble/notifications/NotificationListener.kt +++ b/android/app/src/main/kotlin/io/rebble/cobble/notifications/NotificationListener.kt @@ -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() { @@ -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() diff --git a/android/app/src/main/kotlin/io/rebble/cobble/service/ServiceLifecycleControl.kt b/android/app/src/main/kotlin/io/rebble/cobble/service/ServiceLifecycleControl.kt index df204e73..98c02ef5 100644 --- a/android/app/src/main/kotlin/io/rebble/cobble/service/ServiceLifecycleControl.kt +++ b/android/app/src/main/kotlin/io/rebble/cobble/service/ServiceLifecycleControl.kt @@ -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) )