From d3f9232a3fa50e02af110b5320b4fcf4bcccb3cd Mon Sep 17 00:00:00 2001 From: arkon Date: Tue, 10 May 2022 17:39:45 -0400 Subject: [PATCH] Minor cleanup - Add pending intent immutable flags to satisfy lint warnings - Change AddDuplicateMangaDialog arg to a function instead to avoid leaking controller-specific logic into it - Require WebView 99+ --- app/src/main/java/eu/kanade/tachiyomi/App.kt | 2 +- .../data/library/LibraryUpdateNotifier.kt | 2 +- .../data/notification/NotificationReceiver.kt | 32 +++++++++---------- .../data/updater/AppUpdateChecker.kt | 5 ++- .../data/updater/AppUpdateNotifier.kt | 4 ++- .../ui/manga/AddDuplicateMangaDialog.kt | 12 ++++--- .../tachiyomi/ui/manga/MangaController.kt | 3 +- .../tachiyomi/util/system/WebViewUtil.kt | 2 +- 8 files changed, 36 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index 74ced7ff00..acb62da136 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -99,7 +99,7 @@ open class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { this@App, 0, Intent(ACTION_DISABLE_INCOGNITO_MODE), - PendingIntent.FLAG_ONE_SHOT, + PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE, ) setContentIntent(pendingIntent) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt index b855332678..0fe4733c27 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt @@ -339,7 +339,7 @@ class LibraryUpdateNotifier(private val context: Context) { flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP action = MainActivity.SHORTCUT_RECENTLY_UPDATED } - return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } companion object { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt index 594325527a..47039a174f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt @@ -307,7 +307,7 @@ class NotificationReceiver : BroadcastReceiver() { val intent = Intent(context, NotificationReceiver::class.java).apply { action = ACTION_RESUME_DOWNLOADS } - return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } /** @@ -320,7 +320,7 @@ class NotificationReceiver : BroadcastReceiver() { val intent = Intent(context, NotificationReceiver::class.java).apply { action = ACTION_PAUSE_DOWNLOADS } - return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } /** @@ -333,7 +333,7 @@ class NotificationReceiver : BroadcastReceiver() { val intent = Intent(context, NotificationReceiver::class.java).apply { action = ACTION_CLEAR_DOWNLOADS } - return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } /** @@ -348,7 +348,7 @@ class NotificationReceiver : BroadcastReceiver() { action = ACTION_DISMISS_NOTIFICATION putExtra(EXTRA_NOTIFICATION_ID, notificationId) } - return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } /** @@ -403,7 +403,7 @@ class NotificationReceiver : BroadcastReceiver() { putExtra(EXTRA_FILE_LOCATION, path) putExtra(EXTRA_NOTIFICATION_ID, notificationId) } - return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } /** @@ -420,7 +420,7 @@ class NotificationReceiver : BroadcastReceiver() { putExtra(EXTRA_FILE_LOCATION, path) putExtra(EXTRA_NOTIFICATION_ID, notificationId) } - return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } /** @@ -432,7 +432,7 @@ class NotificationReceiver : BroadcastReceiver() { */ internal fun openChapterPendingActivity(context: Context, manga: Manga, chapter: Chapter): PendingIntent { val newIntent = ReaderActivity.newIntent(context, manga, chapter) - return PendingIntent.getActivity(context, manga.id.hashCode(), newIntent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getActivity(context, manga.id.hashCode(), newIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } /** @@ -448,7 +448,7 @@ class NotificationReceiver : BroadcastReceiver() { .putExtra(MangaController.MANGA_EXTRA, manga.id) .putExtra("notificationId", manga.id.hashCode()) .putExtra("groupId", groupId) - return PendingIntent.getActivity(context, manga.id.hashCode(), newIntent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getActivity(context, manga.id.hashCode(), newIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } /** @@ -470,7 +470,7 @@ class NotificationReceiver : BroadcastReceiver() { putExtra(EXTRA_NOTIFICATION_ID, manga.id.hashCode()) putExtra(EXTRA_GROUP_ID, groupId) } - return PendingIntent.getBroadcast(context, manga.id.hashCode(), newIntent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getBroadcast(context, manga.id.hashCode(), newIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } /** @@ -492,7 +492,7 @@ class NotificationReceiver : BroadcastReceiver() { putExtra(EXTRA_NOTIFICATION_ID, manga.id.hashCode()) putExtra(EXTRA_GROUP_ID, groupId) } - return PendingIntent.getBroadcast(context, manga.id.hashCode(), newIntent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getBroadcast(context, manga.id.hashCode(), newIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } /** @@ -505,7 +505,7 @@ class NotificationReceiver : BroadcastReceiver() { val intent = Intent(context, NotificationReceiver::class.java).apply { action = ACTION_CANCEL_LIBRARY_UPDATE } - return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } /** @@ -519,7 +519,7 @@ class NotificationReceiver : BroadcastReceiver() { action = MainActivity.SHORTCUT_EXTENSIONS addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) } - return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } /** @@ -536,7 +536,7 @@ class NotificationReceiver : BroadcastReceiver() { putExtra(EXTRA_URI, uri) putExtra(EXTRA_NOTIFICATION_ID, notificationId) } - return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } /** @@ -552,7 +552,7 @@ class NotificationReceiver : BroadcastReceiver() { setDataAndType(uri, "text/plain") flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION } - return PendingIntent.getActivity(context, 0, intent, 0) + return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE) } /** @@ -569,7 +569,7 @@ class NotificationReceiver : BroadcastReceiver() { putExtra(EXTRA_URI, uri) putExtra(EXTRA_NOTIFICATION_ID, notificationId) } - return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } /** @@ -584,7 +584,7 @@ class NotificationReceiver : BroadcastReceiver() { action = ACTION_CANCEL_RESTORE putExtra(EXTRA_NOTIFICATION_ID, notificationId) } - return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt index 60460dc982..3688d302fd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt @@ -47,6 +47,7 @@ class AppUpdateChecker { when (result) { is AppUpdateResult.NewUpdate -> AppUpdateNotifier(context).promptUpdate(result.release) is AppUpdateResult.NewUpdateFdroidInstallation -> AppUpdateNotifier(context).promptFdroidUpdate() + else -> {} } result @@ -56,7 +57,6 @@ class AppUpdateChecker { private fun isNewVersion(versionTag: String): Boolean { // Removes prefixes like "r" or "v" val newVersion = versionTag.replace("[^\\d.]".toRegex(), "") - val oldVersion = BuildConfig.VERSION_NAME.replace("[^\\d.]".toRegex(), "") return if (BuildConfig.PREVIEW) { // Preview builds: based on releases in "tachiyomiorg/tachiyomi-preview" repo @@ -65,6 +65,8 @@ class AppUpdateChecker { } else { // Release builds: based on releases in "tachiyomiorg/tachiyomi" repo // tagged as something like "v0.1.2" + val oldVersion = BuildConfig.VERSION_NAME.replace("[^\\d.]".toRegex(), "") + val newSemVer = newVersion.split(".").map { it.toInt() } val oldSemVer = oldVersion.split(".").map { it.toInt() } @@ -73,6 +75,7 @@ class AppUpdateChecker { return true } } + false } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateNotifier.kt index 8d13b89281..25b96cd022 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateNotifier.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.data.updater +import android.annotation.SuppressLint import android.app.PendingIntent import android.content.Context import android.content.Intent @@ -26,12 +27,13 @@ internal class AppUpdateNotifier(private val context: Context) { context.notificationManager.notify(id, build()) } + @SuppressLint("LaunchActivityFromNotification") fun promptUpdate(release: GithubRelease) { val intent = Intent(context, AppUpdateService::class.java).apply { putExtra(AppUpdateService.EXTRA_DOWNLOAD_URL, release.getDownloadLink()) putExtra(AppUpdateService.EXTRA_DOWNLOAD_TITLE, release.version) } - val updateIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + val updateIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) val releaseIntent = Intent(Intent.ACTION_VIEW, release.releaseLink.toUri()).apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/AddDuplicateMangaDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/AddDuplicateMangaDialog.kt index 5121f44cc0..27a06b4fec 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/AddDuplicateMangaDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/AddDuplicateMangaDialog.kt @@ -17,13 +17,17 @@ class AddDuplicateMangaDialog(bundle: Bundle? = null) : DialogController(bund private val sourceManager: SourceManager by injectLazy() private lateinit var libraryManga: Manga - private lateinit var newManga: Manga + private lateinit var onAddToLibrary: () -> Unit - constructor(target: T, libraryManga: Manga, newManga: Manga) : this() { + constructor( + target: T, + libraryManga: Manga, + onAddToLibrary: () -> Unit, + ) : this() { targetController = target this.libraryManga = libraryManga - this.newManga = newManga + this.onAddToLibrary = onAddToLibrary } override fun onCreateDialog(savedViewState: Bundle?): Dialog { @@ -32,7 +36,7 @@ class AddDuplicateMangaDialog(bundle: Bundle? = null) : DialogController(bund return MaterialAlertDialogBuilder(activity!!) .setMessage(activity?.getString(R.string.confirm_manga_add_duplicate, source.name)) .setPositiveButton(activity?.getString(R.string.action_add)) { _, _ -> - (targetController as? Listener)?.addToLibrary(newManga) + onAddToLibrary() } .setNegativeButton(android.R.string.cancel, null) .setNeutralButton(activity?.getString(R.string.action_show_manga)) { _, _ -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index e36f5a2031..cd9bb9ec59 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -521,7 +521,8 @@ class MangaController : } else { val duplicateManga = presenter.getDuplicateLibraryManga(manga) if (duplicateManga != null) { - AddDuplicateMangaDialog(this, duplicateManga, manga).showDialog(router) + AddDuplicateMangaDialog(this, duplicateManga) { addToLibrary(manga) } + .showDialog(router) } else { addToLibrary(manga) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt index af0b83041c..7cc8f3fba1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt @@ -11,7 +11,7 @@ import logcat.LogPriority object WebViewUtil { const val SPOOF_PACKAGE_NAME = "org.chromium.chrome" - const val MINIMUM_WEBVIEW_VERSION = 98 + const val MINIMUM_WEBVIEW_VERSION = 99 fun supportsWebView(context: Context): Boolean { try {