package com.peachpasswords.sync import android.Manifest import android.app.NotificationManager import android.content.Context import android.content.pm.PackageManager import android.os.Build import androidx.core.app.NotificationManagerCompat import androidx.core.content.ContextCompat /** * A foreground service can keep running after Android notification permission * is denied, but its status notification disappears from the drawer. Treat * that as unavailable so the UI never calls background sync visibly "On". */ internal fun canShowBackgroundSyncNotification(context: Context): Boolean { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED ) { return false } if (!NotificationManagerCompat.from(context).areNotificationsEnabled()) return false if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val channel = manager.getNotificationChannel(SYNC_NOTIFICATION_CHANNEL_ID) if (channel?.importance == NotificationManager.IMPORTANCE_NONE) return false } return true }