From a22a1dd2849dcdb11ce9767f356aec2ba96d6adc Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 22 Aug 2020 10:51:32 -0700 Subject: [PATCH] Only offer shortcuts when running as stub --- app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt | 2 +- app/src/main/java/com/topjohnwu/magisk/core/Info.kt | 10 +++++++--- .../topjohnwu/magisk/core/download/ManagerUpgrade.kt | 2 +- .../main/java/com/topjohnwu/magisk/ui/MainActivity.kt | 7 ++----- .../topjohnwu/magisk/ui/settings/SettingsViewModel.kt | 3 ++- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt b/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt index 8dd0d3ec1..044572a89 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt @@ -136,7 +136,7 @@ private class JobSchedulerWrapper(private val base: JobScheduler) : JobScheduler val name = service.className val component = ComponentName( service.packageName, - Info.stub!!.classToComponent[name] ?: name + Info.stubChk.classToComponent[name] ?: name ) javaClass.forceGetDeclaredField("service")?.set(this, component) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Info.kt b/app/src/main/java/com/topjohnwu/magisk/core/Info.kt index 40fc2accf..59956d935 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Info.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Info.kt @@ -18,9 +18,13 @@ object Info { val envRef = CachedValue { loadState() } - @JvmStatic val env by envRef // Local - @JvmStatic var stub: DynAPK.Data? = null // Stub - var remote = UpdateInfo() // Remote + @JvmStatic val env by envRef + + var stub: DynAPK.Data? = null + val stubChk: DynAPK.Data + get() = stub as DynAPK.Data + + var remote = UpdateInfo() // Toggle-able options @JvmStatic var keepVerity = false diff --git a/app/src/main/java/com/topjohnwu/magisk/core/download/ManagerUpgrade.kt b/app/src/main/java/com/topjohnwu/magisk/core/download/ManagerUpgrade.kt index 9c2aaaadb..5f96aaaab 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/download/ManagerUpgrade.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/download/ManagerUpgrade.kt @@ -38,7 +38,7 @@ private suspend fun DownloadService.upgrade(apk: File, id: Int) { // Move to upgrade location apk.copyTo(DynAPK.update(this), overwrite = true) apk.delete() - if (Info.stub!!.version < Info.remote.stub.versionCode) { + if (Info.stubChk.version < Info.remote.stub.versionCode) { // We also want to upgrade stub service.fetchFile(Info.remote.stub.link).byteStream().use { it.writeTo(apk) 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 2f0de7b5d..575b41b24 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt @@ -195,11 +195,8 @@ open class MainActivity : BaseUIActivity( } private fun askForHomeShortcut() { - // Don't bother if we are not hidden - if (packageName == BuildConfig.APPLICATION_ID) - return - - if (!Config.askedHome && ShortcutManagerCompat.isRequestPinShortcutSupported(this)) { + if (isRunningAsStub && !Config.askedHome && + ShortcutManagerCompat.isRequestPinShortcutSupported(this)) { // Ask and show dialog Config.askedHome = true MagiskDialog(this) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt index c0fe69e17..246cf2003 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt @@ -18,6 +18,7 @@ import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.download.Action import com.topjohnwu.magisk.core.download.DownloadService import com.topjohnwu.magisk.core.download.Subject +import com.topjohnwu.magisk.core.isRunningAsStub import com.topjohnwu.magisk.core.utils.PatchAPK import com.topjohnwu.magisk.data.database.RepoDao import com.topjohnwu.magisk.events.AddHomeIconEvent @@ -56,7 +57,7 @@ class SettingsViewModel( // making theming a pain in the ass. Just forget about it list.remove(Theme) } - if (hidden && ShortcutManagerCompat.isRequestPinShortcutSupported(context)) + if (isRunningAsStub && ShortcutManagerCompat.isRequestPinShortcutSupported(context)) list.add(AddShortcut) // Manager