Add stub version to apk comment

This commit is contained in:
vvb2060 2023-02-12 17:40:28 +08:00 committed by John Wu
parent a1a87c9956
commit 5520f0fbf7
5 changed files with 15 additions and 17 deletions

View File

@ -27,9 +27,11 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import timber.log.Timber import timber.log.Timber
import java.io.ByteArrayInputStream
import java.io.IOException import java.io.IOException
import java.io.InputStream import java.io.InputStream
import java.io.OutputStream import java.io.OutputStream
import java.util.Properties
import java.util.zip.ZipEntry import java.util.zip.ZipEntry
import java.util.zip.ZipFile import java.util.zip.ZipFile
import java.util.zip.ZipInputStream import java.util.zip.ZipInputStream
@ -76,7 +78,7 @@ class DownloadService : NotificationService() {
private fun handleApp(stream: InputStream, subject: Subject.App) { private fun handleApp(stream: InputStream, subject: Subject.App) {
fun writeTee(output: OutputStream) { fun writeTee(output: OutputStream) {
val uri = MediaStoreUtils.getFile("${subject.title}.apk").uri val uri = MediaStoreUtils.getFile("${subject.title}.apk").uri
val external = uri.outputStream() val external = uri.outputStream()
stream.copyAndClose(TeeOutputStream(external, output)) stream.copyAndClose(TeeOutputStream(external, output))
} }
@ -87,7 +89,11 @@ class DownloadService : NotificationService() {
// Download full APK to stub update path // Download full APK to stub update path
writeTee(updateApk.outputStream()) 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 // Also upgrade stub
notifyUpdate(subject.notifyId) { notifyUpdate(subject.notifyId) {
it.setProgress(0, 0, true) it.setProgress(0, 0, true)
@ -97,12 +103,12 @@ class DownloadService : NotificationService() {
// Extract stub // Extract stub
val apk = subject.file.toFile() val apk = subject.file.toFile()
val zf = ZipFile(updateApk)
zf.getInputStream(zf.getEntry("assets/stub.apk")).writeTo(apk) zf.getInputStream(zf.getEntry("assets/stub.apk")).writeTo(apk)
zf.close()
// Patch and install // Patch and install
subject.intent = HideAPK.upgrade(this, apk) ?: subject.intent = HideAPK.upgrade(this, apk)
throw IOException("HideAPK patch error") ?: throw IOException("HideAPK patch error")
apk.delete() apk.delete()
} else { } else {
ActivityTracker.foreground?.let { ActivityTracker.foreground?.let {

View File

@ -10,7 +10,6 @@ import androidx.core.net.toUri
import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.Info
import com.topjohnwu.magisk.core.di.AppContext import com.topjohnwu.magisk.core.di.AppContext
import com.topjohnwu.magisk.core.model.MagiskJson 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.model.module.OnlineModule
import com.topjohnwu.magisk.core.utils.MediaStoreUtils import com.topjohnwu.magisk.core.utils.MediaStoreUtils
import com.topjohnwu.magisk.ktx.cachedFile import com.topjohnwu.magisk.ktx.cachedFile
@ -59,7 +58,6 @@ sealed class Subject : Parcelable {
@Parcelize @Parcelize
class App( class App(
private val json: MagiskJson = Info.remote.magisk, private val json: MagiskJson = Info.remote.magisk,
val stub: StubJson = Info.remote.stub,
override val notifyId: Int = Notifications.nextId() override val notifyId: Int = Notifications.nextId()
) : Subject() { ) : Subject() {
override val title: String get() = "Magisk-${json.version}(${json.versionCode})" override val title: String get() = "Magisk-${json.version}(${json.versionCode})"

View File

@ -7,7 +7,6 @@ import kotlinx.parcelize.Parcelize
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class UpdateInfo( data class UpdateInfo(
val magisk: MagiskJson = MagiskJson(), val magisk: MagiskJson = MagiskJson(),
val stub: StubJson = StubJson()
) )
@Parcelize @Parcelize
@ -19,12 +18,6 @@ data class MagiskJson(
val note: String = "" val note: String = ""
) : Parcelable ) : Parcelable
@Parcelize
@JsonClass(generateAdapter = true)
data class StubJson(
val versionCode: Int = -1
) : Parcelable
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class ModuleJson( data class ModuleJson(
val version: String, val version: String,

View File

@ -67,7 +67,6 @@ class HomeViewModel(
val managerInstalledVersion val managerInstalledVersion
get() = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})" + get() = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})" +
Info.stub?.let { " (${it.version})" }.orEmpty() +
if (BuildConfig.DEBUG) " (D)" else "" if (BuildConfig.DEBUG) " (D)" else ""
@get:Bindable @get:Bindable
@ -92,7 +91,7 @@ class HomeViewModel(
val isDebug = Config.updateChannel == Config.Value.DEBUG_CHANNEL val isDebug = Config.updateChannel == Config.Value.DEBUG_CHANNEL
managerRemoteVersion = managerRemoteVersion =
("${magisk.version} (${magisk.versionCode}) (${stub.versionCode})" + ("${magisk.version} (${magisk.versionCode})" +
if (isDebug) " (D)" else "").asText() if (isDebug) " (D)" else "").asText()
} ?: run { } ?: run {
appState = State.INVALID appState = State.INVALID

View File

@ -151,7 +151,9 @@ private fun Project.setupAppCommon() {
val variantCapped = name.replaceFirstChar { it.uppercase() } val variantCapped = name.replaceFirstChar { it.uppercase() }
tasks.getByPath(":$projectName:package$variantCapped").doLast { tasks.getByPath(":$projectName:package$variantCapped").doLast {
val apk = outputs.files.asFileTree.filter { it.name.endsWith(".apk") }.singleFile 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) addComment(apk, signingConfig, android.defaultConfig.minSdk!!, comment)
} }
} }