Skip POST_NOTIFICATIONS permission check for now

Fixes #9265
This commit is contained in:
arkon 2023-03-26 12:34:32 -04:00
parent e932983494
commit 1986042277
10 changed files with 38 additions and 30 deletions

View File

@ -38,9 +38,9 @@ import eu.kanade.tachiyomi.network.NetworkPreferences
import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate
import eu.kanade.tachiyomi.util.system.WebViewUtil import eu.kanade.tachiyomi.util.system.WebViewUtil
import eu.kanade.tachiyomi.util.system.animatorDurationScale import eu.kanade.tachiyomi.util.system.animatorDurationScale
import eu.kanade.tachiyomi.util.system.cancelNotification
import eu.kanade.tachiyomi.util.system.isPreviewBuildType import eu.kanade.tachiyomi.util.system.isPreviewBuildType
import eu.kanade.tachiyomi.util.system.isReleaseBuildType import eu.kanade.tachiyomi.util.system.isReleaseBuildType
import eu.kanade.tachiyomi.util.system.notificationManager
import eu.kanade.tachiyomi.util.system.notify import eu.kanade.tachiyomi.util.system.notify
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
@ -116,7 +116,7 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
} }
} else { } else {
disableIncognitoReceiver.unregister() disableIncognitoReceiver.unregister()
notificationManager.cancel(Notifications.ID_INCOGNITO_MODE) cancelNotification(Notifications.ID_INCOGNITO_MODE)
} }
} }
.launchIn(ProcessLifecycleOwner.get().lifecycleScope) .launchIn(ProcessLifecycleOwner.get().lifecycleScope)

View File

@ -13,8 +13,8 @@ import androidx.work.WorkerParameters
import androidx.work.workDataOf import androidx.work.workDataOf
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.util.system.cancelNotification
import eu.kanade.tachiyomi.util.system.isRunning import eu.kanade.tachiyomi.util.system.isRunning
import eu.kanade.tachiyomi.util.system.notificationManager
import eu.kanade.tachiyomi.util.system.workManager import eu.kanade.tachiyomi.util.system.workManager
import logcat.LogPriority import logcat.LogPriority
import tachiyomi.core.util.system.logcat import tachiyomi.core.util.system.logcat
@ -50,7 +50,7 @@ class BackupCreateJob(private val context: Context, workerParams: WorkerParamete
if (!isAutoBackup) notifier.showBackupError(e.message) if (!isAutoBackup) notifier.showBackupError(e.message)
Result.failure() Result.failure()
} finally { } finally {
context.notificationManager.cancel(Notifications.ID_BACKUP_PROGRESS) context.cancelNotification(Notifications.ID_BACKUP_PROGRESS)
} }
} }

View File

@ -9,8 +9,8 @@ import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.cancelNotification
import eu.kanade.tachiyomi.util.system.notificationBuilder import eu.kanade.tachiyomi.util.system.notificationBuilder
import eu.kanade.tachiyomi.util.system.notificationManager
import eu.kanade.tachiyomi.util.system.notify import eu.kanade.tachiyomi.util.system.notify
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.io.File import java.io.File
@ -51,7 +51,7 @@ class BackupNotifier(private val context: Context) {
} }
fun showBackupError(error: String?) { fun showBackupError(error: String?) {
context.notificationManager.cancel(Notifications.ID_BACKUP_PROGRESS) context.cancelNotification(Notifications.ID_BACKUP_PROGRESS)
with(completeNotificationBuilder) { with(completeNotificationBuilder) {
setContentTitle(context.getString(R.string.creating_backup_error)) setContentTitle(context.getString(R.string.creating_backup_error))
@ -62,7 +62,7 @@ class BackupNotifier(private val context: Context) {
} }
fun showBackupComplete(unifile: UniFile) { fun showBackupComplete(unifile: UniFile) {
context.notificationManager.cancel(Notifications.ID_BACKUP_PROGRESS) context.cancelNotification(Notifications.ID_BACKUP_PROGRESS)
with(completeNotificationBuilder) { with(completeNotificationBuilder) {
setContentTitle(context.getString(R.string.backup_created)) setContentTitle(context.getString(R.string.backup_created))
@ -104,7 +104,7 @@ class BackupNotifier(private val context: Context) {
} }
fun showRestoreError(error: String?) { fun showRestoreError(error: String?) {
context.notificationManager.cancel(Notifications.ID_RESTORE_PROGRESS) context.cancelNotification(Notifications.ID_RESTORE_PROGRESS)
with(completeNotificationBuilder) { with(completeNotificationBuilder) {
setContentTitle(context.getString(R.string.restoring_backup_error)) setContentTitle(context.getString(R.string.restoring_backup_error))
@ -115,7 +115,7 @@ class BackupNotifier(private val context: Context) {
} }
fun showRestoreComplete(time: Long, errorCount: Int, path: String?, file: String?) { fun showRestoreComplete(time: Long, errorCount: Int, path: String?, file: String?) {
context.notificationManager.cancel(Notifications.ID_RESTORE_PROGRESS) context.cancelNotification(Notifications.ID_RESTORE_PROGRESS)
val timeString = context.getString( val timeString = context.getString(
R.string.restore_duration, R.string.restore_duration,

View File

@ -11,8 +11,8 @@ import androidx.work.WorkerParameters
import androidx.work.workDataOf import androidx.work.workDataOf
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.util.system.cancelNotification
import eu.kanade.tachiyomi.util.system.isRunning import eu.kanade.tachiyomi.util.system.isRunning
import eu.kanade.tachiyomi.util.system.notificationManager
import eu.kanade.tachiyomi.util.system.workManager import eu.kanade.tachiyomi.util.system.workManager
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import logcat.LogPriority import logcat.LogPriority
@ -47,7 +47,7 @@ class BackupRestoreJob(private val context: Context, workerParams: WorkerParamet
Result.failure() Result.failure()
} }
} finally { } finally {
context.notificationManager.cancel(Notifications.ID_RESTORE_PROGRESS) context.cancelNotification(Notifications.ID_RESTORE_PROGRESS)
} }
} }

View File

@ -11,8 +11,8 @@ import eu.kanade.tachiyomi.data.notification.NotificationHandler
import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.util.lang.chop import eu.kanade.tachiyomi.util.lang.chop
import eu.kanade.tachiyomi.util.system.cancelNotification
import eu.kanade.tachiyomi.util.system.notificationBuilder import eu.kanade.tachiyomi.util.system.notificationBuilder
import eu.kanade.tachiyomi.util.system.notificationManager
import eu.kanade.tachiyomi.util.system.notify import eu.kanade.tachiyomi.util.system.notify
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.util.regex.Pattern import java.util.regex.Pattern
@ -59,7 +59,7 @@ internal class DownloadNotifier(private val context: Context) {
* those can only be dismissed by the user. * those can only be dismissed by the user.
*/ */
fun dismissProgress() { fun dismissProgress() {
context.notificationManager.cancel(Notifications.ID_DOWNLOAD_CHAPTER_PROGRESS) context.cancelNotification(Notifications.ID_DOWNLOAD_CHAPTER_PROGRESS)
} }
/** /**

View File

@ -21,8 +21,8 @@ import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.util.lang.chop import eu.kanade.tachiyomi.util.lang.chop
import eu.kanade.tachiyomi.util.system.cancelNotification
import eu.kanade.tachiyomi.util.system.notificationBuilder import eu.kanade.tachiyomi.util.system.notificationBuilder
import eu.kanade.tachiyomi.util.system.notificationManager
import eu.kanade.tachiyomi.util.system.notify import eu.kanade.tachiyomi.util.system.notify
import tachiyomi.core.Constants import tachiyomi.core.Constants
import tachiyomi.core.util.lang.launchUI import tachiyomi.core.util.lang.launchUI
@ -265,7 +265,7 @@ class LibraryUpdateNotifier(private val context: Context) {
* Cancels the progress notification. * Cancels the progress notification.
*/ */
fun cancelProgressNotification() { fun cancelProgressNotification() {
context.notificationManager.cancel(Notifications.ID_LIBRARY_PROGRESS) context.cancelNotification(Notifications.ID_LIBRARY_PROGRESS)
} }
private suspend fun getMangaIcon(manga: Manga): Bitmap? { private suspend fun getMangaIcon(manga: Manga): Bitmap? {

View File

@ -16,6 +16,7 @@ import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.util.storage.DiskUtil import eu.kanade.tachiyomi.util.storage.DiskUtil
import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.cancelNotification
import eu.kanade.tachiyomi.util.system.getParcelableExtraCompat import eu.kanade.tachiyomi.util.system.getParcelableExtraCompat
import eu.kanade.tachiyomi.util.system.notificationManager import eu.kanade.tachiyomi.util.system.notificationManager
import eu.kanade.tachiyomi.util.system.toShareIntent import eu.kanade.tachiyomi.util.system.toShareIntent
@ -135,7 +136,7 @@ class NotificationReceiver : BroadcastReceiver() {
* @param notificationId the id of the notification * @param notificationId the id of the notification
*/ */
private fun dismissNotification(context: Context, notificationId: Int) { private fun dismissNotification(context: Context, notificationId: Int) {
context.notificationManager.cancel(notificationId) context.cancelNotification(notificationId)
} }
/** /**
@ -380,13 +381,13 @@ class NotificationReceiver : BroadcastReceiver() {
} }
if (notifications.size == 2) { if (notifications.size == 2) {
context.notificationManager.cancel(groupId) context.cancelNotification(groupId)
return return
} }
} }
} }
context.notificationManager.cancel(notificationId) context.cancelNotification(notificationId)
} }
/** /**

View File

@ -12,8 +12,8 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.notification.NotificationHandler import eu.kanade.tachiyomi.data.notification.NotificationHandler
import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.util.system.cancelNotification
import eu.kanade.tachiyomi.util.system.notificationBuilder import eu.kanade.tachiyomi.util.system.notificationBuilder
import eu.kanade.tachiyomi.util.system.notificationManager
import eu.kanade.tachiyomi.util.system.notify import eu.kanade.tachiyomi.util.system.notify
/** /**
@ -50,7 +50,7 @@ class SaveImageNotifier(private val context: Context) {
* Clears the notification message. * Clears the notification message.
*/ */
fun onClear() { fun onClear() {
context.notificationManager.cancel(notificationId) context.cancelNotification(notificationId)
} }
/** /**

View File

@ -8,8 +8,8 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.cancelNotification
import eu.kanade.tachiyomi.util.system.createFileInCacheDir import eu.kanade.tachiyomi.util.system.createFileInCacheDir
import eu.kanade.tachiyomi.util.system.notificationManager
import eu.kanade.tachiyomi.util.system.notify import eu.kanade.tachiyomi.util.system.notify
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import tachiyomi.core.util.lang.withNonCancellableContext import tachiyomi.core.util.lang.withNonCancellableContext
@ -43,7 +43,7 @@ class CrashLogUtil(private val context: Context) {
} }
private fun showNotification(uri: Uri) { private fun showNotification(uri: Uri) {
context.notificationManager.cancel(Notifications.ID_CRASH_LOGS) context.cancelNotification(Notifications.ID_CRASH_LOGS)
context.notify( context.notify(
Notifications.ID_CRASH_LOGS, Notifications.ID_CRASH_LOGS,

View File

@ -1,6 +1,6 @@
package eu.kanade.tachiyomi.util.system package eu.kanade.tachiyomi.util.system
import android.Manifest import android.annotation.SuppressLint
import android.app.Notification import android.app.Notification
import android.app.NotificationManager import android.app.NotificationManager
import android.content.Context import android.content.Context
@ -9,7 +9,6 @@ import androidx.core.app.NotificationChannelGroupCompat
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import androidx.core.app.NotificationManagerCompat.NotificationWithIdAndTag import androidx.core.app.NotificationManagerCompat.NotificationWithIdAndTag
import androidx.core.content.PermissionChecker
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -21,22 +20,30 @@ fun Context.notify(id: Int, channelId: String, block: (NotificationCompat.Builde
this.notify(id, notification) this.notify(id, notification)
} }
@SuppressLint("MissingPermission")
fun Context.notify(id: Int, notification: Notification) { fun Context.notify(id: Int, notification: Notification) {
if (PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) { // TODO: check for permission once targeting SDK 33+
return // if (PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) {
} // return
// }
NotificationManagerCompat.from(this).notify(id, notification) NotificationManagerCompat.from(this).notify(id, notification)
} }
@SuppressLint("MissingPermission")
fun Context.notify(notificationWithIdAndTags: List<NotificationWithIdAndTag>) { fun Context.notify(notificationWithIdAndTags: List<NotificationWithIdAndTag>) {
if (PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) { // TODO: check for permission once targeting SDK 33+
return // if (PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) {
} // return
// }
NotificationManagerCompat.from(this).notify(notificationWithIdAndTags) NotificationManagerCompat.from(this).notify(notificationWithIdAndTags)
} }
fun Context.cancelNotification(id: Int) {
NotificationManagerCompat.from(this).cancel(id)
}
/** /**
* Helper method to create a notification builder. * Helper method to create a notification builder.
* *