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.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 {

View File

@ -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})"

View File

@ -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,

View File

@ -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

View File

@ -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)
}
}