From 77a275cbcd07fe57aedd05ff9303bf1118e01c4c Mon Sep 17 00:00:00 2001 From: vvb2060 Date: Mon, 14 Feb 2022 23:15:46 +0800 Subject: [PATCH] Show notification when stub is updated to full --- app/src/main/java/com/topjohnwu/magisk/core/Config.kt | 2 -- app/src/main/java/com/topjohnwu/magisk/core/Receiver.kt | 5 +++-- .../topjohnwu/magisk/core/download/DownloadService.kt | 9 ++------- .../main/java/com/topjohnwu/magisk/ui/MainActivity.kt | 1 - .../main/java/com/topjohnwu/magisk/view/Notifications.kt | 1 + 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Config.kt b/app/src/main/java/com/topjohnwu/magisk/core/Config.kt index af7cceb3e..e5b283002 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Config.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Config.kt @@ -61,7 +61,6 @@ object Config : PreferenceModel, DBConfig { const val BOOT_ID = "boot_id" const val ASKED_HOME = "asked_home" const val DOH = "doh" - const val SHOW_UPDATE_DONE = "update_done" } object Value { @@ -134,7 +133,6 @@ object Config : PreferenceModel, DBConfig { var suTapjack by preference(Key.SU_TAPJACK, true) var checkUpdate by preference(Key.CHECK_UPDATES, true) var doh by preference(Key.DOH, false) - var showUpdateDone by preference(Key.SHOW_UPDATE_DONE, false) var showSystemApp by preference(Key.SHOW_SYSTEM_APP, false) var customChannelUrl by preference(Key.CUSTOM_CHANNEL, "") diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Receiver.kt b/app/src/main/java/com/topjohnwu/magisk/core/Receiver.kt index fa986db96..7d639ee1f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Receiver.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Receiver.kt @@ -47,9 +47,10 @@ open class Receiver : BaseReceiver() { } Intent.ACTION_LOCALE_CHANGED -> Shortcuts.setupDynamic(context) Intent.ACTION_MY_PACKAGE_REPLACED -> { - if (Config.showUpdateDone) { + @Suppress("DEPRECATION") + val installer = context.packageManager.getInstallerPackageName(context.packageName) + if (installer == context.packageName) { Notifications.updateDone(context) - Config.showUpdateDone = false } } } diff --git a/app/src/main/java/com/topjohnwu/magisk/core/download/DownloadService.kt b/app/src/main/java/com/topjohnwu/magisk/core/download/DownloadService.kt index 890328022..8dd591021 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/download/DownloadService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/download/DownloadService.kt @@ -75,11 +75,6 @@ class DownloadService : NotificationService() { } } - private fun APKInstall.Session.open(): OutputStream { - Config.showUpdateDone = true - return openStream(this@DownloadService) - } - private suspend fun handleApp(stream: InputStream, subject: Subject.App) { fun writeTee(output: OutputStream) { val uri = MediaStoreUtils.getFile("${subject.title}.apk").uri @@ -115,7 +110,7 @@ class DownloadService : NotificationService() { // Install val session = APKInstall.startSession(this) - patched.inputStream().copyAndClose(session.open()) + patched.inputStream().copyAndClose(session.openStream(this)) subject.intent = session.waitIntent() patched.delete() @@ -137,7 +132,7 @@ class DownloadService : NotificationService() { } } else { val session = APKInstall.startSession(this) - writeTee(session.open()) + writeTee(session.openStream(this)) subject.intent = session.waitIntent() } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt index b2e9aa90b..7929dbb82 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt @@ -51,7 +51,6 @@ class MainActivity : BaseMainActivity() { setContentView() showUnsupportedMessage() askForHomeShortcut() - Config.showUpdateDone = false window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) diff --git a/app/src/main/java/com/topjohnwu/magisk/view/Notifications.kt b/app/src/main/java/com/topjohnwu/magisk/view/Notifications.kt index b7195c722..f7e9846da 100644 --- a/app/src/main/java/com/topjohnwu/magisk/view/Notifications.kt +++ b/app/src/main/java/com/topjohnwu/magisk/view/Notifications.kt @@ -52,6 +52,7 @@ object Notifications { @SuppressLint("InlinedApi") fun updateDone(context: Context) { + setup(context) val flag = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT val pending = PendingIntent.getActivity(context, 0, selfLaunchIntent(context), flag) val builder = if (SDK_INT >= 26) {