From 80d7d751c53db60d5bae951a0b651b446d89459a Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Wed, 19 Jan 2022 12:08:29 +0530 Subject: [PATCH 1/5] check notificationState and return null notification --- .../java/com/fsck/k9/controller/push/PushService.kt | 4 +++- .../fsck/k9/notification/PushNotificationManager.kt | 13 ++++++++++--- .../com/fsck/k9/resources/K9CoreResourceProvider.kt | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/core/src/main/java/com/fsck/k9/controller/push/PushService.kt b/app/core/src/main/java/com/fsck/k9/controller/push/PushService.kt index 90c9fe33a6..f39b0827cc 100644 --- a/app/core/src/main/java/com/fsck/k9/controller/push/PushService.kt +++ b/app/core/src/main/java/com/fsck/k9/controller/push/PushService.kt @@ -42,7 +42,9 @@ class PushService : Service() { val notification = pushNotificationManager.createForegroundNotification() if (Build.VERSION.SDK_INT >= 29) { - startForeground(notificationId, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC) + if (notification != null) { + startForeground(notificationId, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC) + } } else { startForeground(notificationId, notification) } diff --git a/app/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt b/app/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt index bd15f47801..036347956a 100644 --- a/app/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt +++ b/app/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt @@ -33,7 +33,7 @@ internal class PushNotificationManager( private var isForegroundServiceStarted = false @Synchronized - fun createForegroundNotification(): Notification { + fun createForegroundNotification(): Notification? { isForegroundServiceStarted = true return createNotification() } @@ -45,10 +45,12 @@ internal class PushNotificationManager( private fun updateNotification() { val notification = createNotification() - notificationManager.notify(notificationId, notification) + if (notification != null) { + notificationManager.notify(notificationId, notification) + } } - private fun createNotification(): Notification { + private fun createNotification(): Notification? { val intent = Intent(PUSH_INFO_ACTION).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) @@ -57,6 +59,11 @@ internal class PushNotificationManager( val flag = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0 val contentIntent = PendingIntent.getActivity(context, 1, intent, flag) + if(notificationState==PushNotificationState.LISTENING){ + + return null; + } + return NotificationCompat.Builder(context, notificationChannelManager.pushChannelId) .setSmallIcon(resourceProvider.iconPushNotification) .setContentTitle(resourceProvider.pushNotificationText(notificationState)) diff --git a/app/k9mail/src/main/java/com/fsck/k9/resources/K9CoreResourceProvider.kt b/app/k9mail/src/main/java/com/fsck/k9/resources/K9CoreResourceProvider.kt index 270736c3ee..0754dcaa04 100644 --- a/app/k9mail/src/main/java/com/fsck/k9/resources/K9CoreResourceProvider.kt +++ b/app/k9mail/src/main/java/com/fsck/k9/resources/K9CoreResourceProvider.kt @@ -49,4 +49,4 @@ class K9CoreResourceProvider(private val context: Context) : CoreResourceProvide } override fun pushNotificationInfoText(): String = context.getString(R.string.push_notification_info) -} +} \ No newline at end of file -- GitLab From ce58a884f6630f61e7b63bbd870f9306854a309b Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Wed, 19 Jan 2022 12:13:51 +0530 Subject: [PATCH 2/5] build fix --- .../main/java/com/fsck/k9/resources/K9CoreResourceProvider.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/k9mail/src/main/java/com/fsck/k9/resources/K9CoreResourceProvider.kt b/app/k9mail/src/main/java/com/fsck/k9/resources/K9CoreResourceProvider.kt index 0754dcaa04..270736c3ee 100644 --- a/app/k9mail/src/main/java/com/fsck/k9/resources/K9CoreResourceProvider.kt +++ b/app/k9mail/src/main/java/com/fsck/k9/resources/K9CoreResourceProvider.kt @@ -49,4 +49,4 @@ class K9CoreResourceProvider(private val context: Context) : CoreResourceProvide } override fun pushNotificationInfoText(): String = context.getString(R.string.push_notification_info) -} \ No newline at end of file +} -- GitLab From 011784c111d633583c90bd02ef0de79932f4474f Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Thu, 20 Jan 2022 10:50:29 +0530 Subject: [PATCH 3/5] revert Hide permission notification part --- .../main/java/com/fsck/k9/controller/push/PushService.kt | 2 -- .../com/fsck/k9/notification/PushNotificationManager.kt | 9 ++------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/app/core/src/main/java/com/fsck/k9/controller/push/PushService.kt b/app/core/src/main/java/com/fsck/k9/controller/push/PushService.kt index f39b0827cc..cc132e7d62 100644 --- a/app/core/src/main/java/com/fsck/k9/controller/push/PushService.kt +++ b/app/core/src/main/java/com/fsck/k9/controller/push/PushService.kt @@ -42,9 +42,7 @@ class PushService : Service() { val notification = pushNotificationManager.createForegroundNotification() if (Build.VERSION.SDK_INT >= 29) { - if (notification != null) { startForeground(notificationId, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC) - } } else { startForeground(notificationId, notification) } diff --git a/app/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt b/app/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt index 036347956a..79b25a3735 100644 --- a/app/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt +++ b/app/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt @@ -33,7 +33,7 @@ internal class PushNotificationManager( private var isForegroundServiceStarted = false @Synchronized - fun createForegroundNotification(): Notification? { + fun createForegroundNotification(): Notification { isForegroundServiceStarted = true return createNotification() } @@ -50,7 +50,7 @@ internal class PushNotificationManager( } } - private fun createNotification(): Notification? { + private fun createNotification(): Notification { val intent = Intent(PUSH_INFO_ACTION).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) @@ -59,11 +59,6 @@ internal class PushNotificationManager( val flag = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0 val contentIntent = PendingIntent.getActivity(context, 1, intent, flag) - if(notificationState==PushNotificationState.LISTENING){ - - return null; - } - return NotificationCompat.Builder(context, notificationChannelManager.pushChannelId) .setSmallIcon(resourceProvider.iconPushNotification) .setContentTitle(resourceProvider.pushNotificationText(notificationState)) -- GitLab From 34afcc2fd79f8488a986f216d906f99b61fd9876 Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Thu, 20 Jan 2022 12:48:06 +0530 Subject: [PATCH 4/5] update foreGround service for <28 SDK version --- .../src/main/java/com/fsck/k9/controller/push/PushService.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/core/src/main/java/com/fsck/k9/controller/push/PushService.kt b/app/core/src/main/java/com/fsck/k9/controller/push/PushService.kt index cc132e7d62..58077f239b 100644 --- a/app/core/src/main/java/com/fsck/k9/controller/push/PushService.kt +++ b/app/core/src/main/java/com/fsck/k9/controller/push/PushService.kt @@ -42,7 +42,8 @@ class PushService : Service() { val notification = pushNotificationManager.createForegroundNotification() if (Build.VERSION.SDK_INT >= 29) { - startForeground(notificationId, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC) + // startForeground(notificationId, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC) + startForeground(notificationId, notification) } else { startForeground(notificationId, notification) } -- GitLab From b2a8e295957ba4b8fe06e2dfc32125a6331b1464 Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Thu, 20 Jan 2022 13:08:27 +0530 Subject: [PATCH 5/5] update foreGround service for <28 SDK version --- .../src/main/java/com/fsck/k9/controller/push/PushService.kt | 5 ++--- .../java/com/fsck/k9/controller/push/PushServiceManager.kt | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/core/src/main/java/com/fsck/k9/controller/push/PushService.kt b/app/core/src/main/java/com/fsck/k9/controller/push/PushService.kt index 58077f239b..a24baf9de1 100644 --- a/app/core/src/main/java/com/fsck/k9/controller/push/PushService.kt +++ b/app/core/src/main/java/com/fsck/k9/controller/push/PushService.kt @@ -25,7 +25,7 @@ class PushService : Service() { Timber.v("PushService.onStartCommand()") super.onStartCommand(intent, flags, startId) - startForeground() + // startForeground() initializePushController() return START_STICKY @@ -42,8 +42,7 @@ class PushService : Service() { val notification = pushNotificationManager.createForegroundNotification() if (Build.VERSION.SDK_INT >= 29) { - // startForeground(notificationId, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC) - startForeground(notificationId, notification) + startForeground(notificationId, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC) } else { startForeground(notificationId, notification) } diff --git a/app/core/src/main/java/com/fsck/k9/controller/push/PushServiceManager.kt b/app/core/src/main/java/com/fsck/k9/controller/push/PushServiceManager.kt index 41df5b710e..e55bf3ee4a 100644 --- a/app/core/src/main/java/com/fsck/k9/controller/push/PushServiceManager.kt +++ b/app/core/src/main/java/com/fsck/k9/controller/push/PushServiceManager.kt @@ -34,7 +34,8 @@ internal class PushServiceManager(private val context: Context) { try { val intent = Intent(context, PushService::class.java) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - context.startForegroundService(intent) + // context.startForegroundService(intent) + context.startService(intent) } else { context.startService(intent) } -- GitLab