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 76cc8e406..ba4804ab1 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 @@ -27,9 +27,11 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.launch import timber.log.Timber +import java.io.ByteArrayInputStream import java.io.IOException import java.io.InputStream import java.io.OutputStream +import java.util.Properties import java.util.zip.ZipEntry import java.util.zip.ZipFile import java.util.zip.ZipInputStream @@ -76,7 +78,7 @@ class DownloadService : NotificationService() { private fun handleApp(stream: InputStream, subject: Subject.App) { fun writeTee(output: OutputStream) { - val uri = MediaStoreUtils.getFile("${subject.title}.apk").uri + val uri = MediaStoreUtils.getFile("${subject.title}.apk").uri val external = uri.outputStream() stream.copyAndClose(TeeOutputStream(external, output)) } @@ -87,7 +89,11 @@ class DownloadService : NotificationService() { // Download full APK to stub update path writeTee(updateApk.outputStream()) - if (Info.stub!!.version < subject.stub.versionCode) { + val zf = ZipFile(updateApk) + val prop = Properties() + prop.load(ByteArrayInputStream(zf.comment.toByteArray())) + val stubVersion = prop.getProperty("stubVersion").toIntOrNull() ?: -1 + if (Info.stub!!.version < stubVersion) { // Also upgrade stub notifyUpdate(subject.notifyId) { it.setProgress(0, 0, true) @@ -97,12 +103,12 @@ class DownloadService : NotificationService() { // Extract stub val apk = subject.file.toFile() - val zf = ZipFile(updateApk) zf.getInputStream(zf.getEntry("assets/stub.apk")).writeTo(apk) + zf.close() // Patch and install - subject.intent = HideAPK.upgrade(this, apk) ?: - throw IOException("HideAPK patch error") + subject.intent = HideAPK.upgrade(this, apk) + ?: throw IOException("HideAPK patch error") apk.delete() } else { ActivityTracker.foreground?.let { diff --git a/app/src/main/java/com/topjohnwu/magisk/core/download/Subject.kt b/app/src/main/java/com/topjohnwu/magisk/core/download/Subject.kt index fdac8b0fe..5e0e777c8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/download/Subject.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/download/Subject.kt @@ -10,7 +10,6 @@ import androidx.core.net.toUri import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.di.AppContext import com.topjohnwu.magisk.core.model.MagiskJson -import com.topjohnwu.magisk.core.model.StubJson import com.topjohnwu.magisk.core.model.module.OnlineModule import com.topjohnwu.magisk.core.utils.MediaStoreUtils import com.topjohnwu.magisk.ktx.cachedFile @@ -59,7 +58,6 @@ sealed class Subject : Parcelable { @Parcelize class App( private val json: MagiskJson = Info.remote.magisk, - val stub: StubJson = Info.remote.stub, override val notifyId: Int = Notifications.nextId() ) : Subject() { override val title: String get() = "Magisk-${json.version}(${json.versionCode})" diff --git a/app/src/main/java/com/topjohnwu/magisk/core/model/UpdateInfo.kt b/app/src/main/java/com/topjohnwu/magisk/core/model/UpdateInfo.kt index c4ece722b..60b3a11d4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/model/UpdateInfo.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/model/UpdateInfo.kt @@ -7,7 +7,6 @@ import kotlinx.parcelize.Parcelize @JsonClass(generateAdapter = true) data class UpdateInfo( val magisk: MagiskJson = MagiskJson(), - val stub: StubJson = StubJson() ) @Parcelize @@ -19,12 +18,6 @@ data class MagiskJson( val note: String = "" ) : Parcelable -@Parcelize -@JsonClass(generateAdapter = true) -data class StubJson( - val versionCode: Int = -1 -) : Parcelable - @JsonClass(generateAdapter = true) data class ModuleJson( val version: String, diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt index e20bf5f0f..b107a9ffb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt @@ -67,7 +67,6 @@ class HomeViewModel( val managerInstalledVersion get() = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})" + - Info.stub?.let { " (${it.version})" }.orEmpty() + if (BuildConfig.DEBUG) " (D)" else "" @get:Bindable @@ -92,7 +91,7 @@ class HomeViewModel( val isDebug = Config.updateChannel == Config.Value.DEBUG_CHANNEL managerRemoteVersion = - ("${magisk.version} (${magisk.versionCode}) (${stub.versionCode})" + + ("${magisk.version} (${magisk.versionCode})" + if (isDebug) " (D)" else "").asText() } ?: run { appState = State.INVALID diff --git a/buildSrc/src/main/java/Setup.kt b/buildSrc/src/main/java/Setup.kt index 69856dc3e..0c2a4a949 100644 --- a/buildSrc/src/main/java/Setup.kt +++ b/buildSrc/src/main/java/Setup.kt @@ -151,7 +151,9 @@ private fun Project.setupAppCommon() { val variantCapped = name.replaceFirstChar { it.uppercase() } tasks.getByPath(":$projectName:package$variantCapped").doLast { val apk = outputs.files.asFileTree.filter { it.name.endsWith(".apk") }.singleFile - val comment = "version=${Config.version}\nversionCode=${Config.versionCode}" + val comment = "version=${Config.version}\n" + + "versionCode=${Config.versionCode}\n" + + "stubVersion=${Config.stubVersion}}\n" addComment(apk, signingConfig, android.defaultConfig.minSdk!!, comment) } }