|
|
|
@ -1,5 +1,6 @@
|
|
|
|
package com.onlinemsg.client.service
|
|
|
|
package com.onlinemsg.client.service
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.Manifest
|
|
|
|
import android.app.Notification
|
|
|
|
import android.app.Notification
|
|
|
|
import android.app.NotificationChannel
|
|
|
|
import android.app.NotificationChannel
|
|
|
|
import android.app.NotificationManager
|
|
|
|
import android.app.NotificationManager
|
|
|
|
@ -7,6 +8,7 @@ import android.app.PendingIntent
|
|
|
|
import android.app.Service
|
|
|
|
import android.app.Service
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Intent
|
|
|
|
import android.content.Intent
|
|
|
|
|
|
|
|
import android.content.pm.PackageManager
|
|
|
|
import android.os.Build
|
|
|
|
import android.os.Build
|
|
|
|
import android.os.IBinder
|
|
|
|
import android.os.IBinder
|
|
|
|
import androidx.core.app.NotificationCompat
|
|
|
|
import androidx.core.app.NotificationCompat
|
|
|
|
@ -69,10 +71,18 @@ class ChatForegroundService : Service() {
|
|
|
|
.map { it.status to it.statusHint }
|
|
|
|
.map { it.status to it.statusHint }
|
|
|
|
.distinctUntilChanged()
|
|
|
|
.distinctUntilChanged()
|
|
|
|
.collect { (status, hint) ->
|
|
|
|
.collect { (status, hint) ->
|
|
|
|
NotificationManagerCompat.from(this@ChatForegroundService).notify(
|
|
|
|
val canNotify = Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU ||
|
|
|
|
FOREGROUND_NOTIFICATION_ID,
|
|
|
|
checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED
|
|
|
|
buildForegroundNotification(status, hint)
|
|
|
|
if (canNotify) {
|
|
|
|
)
|
|
|
|
try {
|
|
|
|
|
|
|
|
NotificationManagerCompat.from(this@ChatForegroundService).notify(
|
|
|
|
|
|
|
|
FOREGROUND_NOTIFICATION_ID,
|
|
|
|
|
|
|
|
buildForegroundNotification(status, hint)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
} catch (_: SecurityException) {
|
|
|
|
|
|
|
|
// Permission may be revoked while service is running.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (status == ConnectionStatus.IDLE && !ChatSessionManager.shouldForegroundServiceRun()) {
|
|
|
|
if (status == ConnectionStatus.IDLE && !ChatSessionManager.shouldForegroundServiceRun()) {
|
|
|
|
stopForeground(STOP_FOREGROUND_REMOVE)
|
|
|
|
stopForeground(STOP_FOREGROUND_REMOVE)
|
|
|
|
stopSelf()
|
|
|
|
stopSelf()
|
|
|
|
|