mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-28 18:47:48 +00:00
Cleanup UpdateInfo
This commit is contained in:
parent
4a3f5dc619
commit
bf9ac8252b
@ -1,26 +1,20 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.topjohnwu.magisk.model.entity.UpdateInfo;
|
||||
import com.topjohnwu.superuser.Shell;
|
||||
import com.topjohnwu.superuser.ShellUtils;
|
||||
|
||||
public final class Info {
|
||||
|
||||
public static int magiskVersionCode = -1;
|
||||
// Current status
|
||||
public static String magiskVersionString = "";
|
||||
// Update Info
|
||||
public static String remoteMagiskVersionString = "";
|
||||
public static int remoteMagiskVersionCode = -1;
|
||||
public static String magiskLink = "";
|
||||
public static String magiskNoteLink = "";
|
||||
public static String magiskMD5 = "";
|
||||
public static String remoteManagerVersionString = "";
|
||||
public static int remoteManagerVersionCode = -1;
|
||||
public static String managerLink = "";
|
||||
public static String managerNoteLink = "";
|
||||
public static String uninstallerLink = "";
|
||||
|
||||
// Install flags
|
||||
@NonNull
|
||||
public static String magiskVersionString = "";
|
||||
|
||||
public static UpdateInfo remote = new UpdateInfo();
|
||||
|
||||
public static boolean keepVerity = false;
|
||||
public static boolean keepEnc = false;
|
||||
public static boolean recovery = false;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.topjohnwu.magisk.data.network
|
||||
|
||||
import com.topjohnwu.magisk.Const
|
||||
import com.topjohnwu.magisk.model.entity.MagiskConfig
|
||||
import com.topjohnwu.magisk.model.entity.UpdateInfo
|
||||
import io.reactivex.Single
|
||||
import okhttp3.ResponseBody
|
||||
import retrofit2.http.GET
|
||||
@ -15,19 +15,19 @@ interface GithubRawApiServices {
|
||||
//region topjohnwu/magisk_files
|
||||
|
||||
@GET("$MAGISK_FILES/master/stable.json")
|
||||
fun fetchStableUpdate(): Single<MagiskConfig>
|
||||
fun fetchStableUpdate(): Single<UpdateInfo>
|
||||
|
||||
@GET("$MAGISK_FILES/master/beta.json")
|
||||
fun fetchBetaUpdate(): Single<MagiskConfig>
|
||||
fun fetchBetaUpdate(): Single<UpdateInfo>
|
||||
|
||||
@GET("$MAGISK_FILES/master/canary_builds/release.json")
|
||||
fun fetchCanaryUpdate(): Single<MagiskConfig>
|
||||
fun fetchCanaryUpdate(): Single<UpdateInfo>
|
||||
|
||||
@GET("$MAGISK_FILES/master/canary_builds/canary.json")
|
||||
fun fetchCanaryDebugUpdate(): Single<MagiskConfig>
|
||||
fun fetchCanaryDebugUpdate(): Single<UpdateInfo>
|
||||
|
||||
@GET
|
||||
fun fetchCustomUpdate(@Url url: String): Single<MagiskConfig>
|
||||
fun fetchCustomUpdate(@Url url: String): Single<UpdateInfo>
|
||||
|
||||
@GET("$MAGISK_FILES/{$REVISION}/snet.apk")
|
||||
@Streaming
|
||||
|
@ -50,27 +50,14 @@ class MagiskRepository(
|
||||
else -> throw IllegalArgumentException()
|
||||
}.flatMap {
|
||||
// If remote version is lower than current installed, try switching to beta
|
||||
if (it.magisk.versionCode.toIntOrNull() ?: -1 < Info.magiskVersionCode
|
||||
if (it.magisk.versionCode < Info.magiskVersionCode
|
||||
&& Config.updateChannel == Config.Value.DEFAULT_CHANNEL) {
|
||||
Config.updateChannel = Config.Value.BETA_CHANNEL
|
||||
apiRaw.fetchBetaUpdate()
|
||||
} else {
|
||||
Single.just(it)
|
||||
}
|
||||
}.doOnSuccess {
|
||||
Info.remoteMagiskVersionString = it.magisk.version
|
||||
Info.remoteMagiskVersionCode = it.magisk.versionCode.toIntOrNull() ?: -1
|
||||
Info.magiskLink = it.magisk.link
|
||||
Info.magiskNoteLink = it.magisk.note
|
||||
Info.magiskMD5 = it.magisk.hash
|
||||
|
||||
Info.remoteManagerVersionString = it.app.version
|
||||
Info.remoteManagerVersionCode = it.app.versionCode.toIntOrNull() ?: -1
|
||||
Info.managerLink = it.app.link
|
||||
Info.managerNoteLink = it.app.note
|
||||
|
||||
Info.uninstallerLink = it.uninstaller.link
|
||||
}
|
||||
}.map { Info.remote = it; it }
|
||||
|
||||
fun fetchApps() =
|
||||
Single.fromCallable { packageManager.getInstalledApplications(0) }
|
||||
|
@ -1,11 +0,0 @@
|
||||
package com.topjohnwu.magisk.model.entity
|
||||
|
||||
import se.ansman.kotshi.JsonSerializable
|
||||
|
||||
@JsonSerializable
|
||||
data class MagiskApp(
|
||||
val version: String,
|
||||
val versionCode: String,
|
||||
val link: String,
|
||||
val note: String
|
||||
)
|
@ -1,10 +0,0 @@
|
||||
package com.topjohnwu.magisk.model.entity
|
||||
|
||||
import se.ansman.kotshi.JsonSerializable
|
||||
|
||||
@JsonSerializable
|
||||
data class MagiskConfig(
|
||||
val app: MagiskApp,
|
||||
val uninstaller: MagiskLink,
|
||||
val magisk: MagiskFlashable
|
||||
)
|
@ -1,13 +0,0 @@
|
||||
package com.topjohnwu.magisk.model.entity
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import se.ansman.kotshi.JsonSerializable
|
||||
|
||||
@JsonSerializable
|
||||
data class MagiskFlashable(
|
||||
val version: String,
|
||||
val versionCode: String,
|
||||
val link: String,
|
||||
val note: String,
|
||||
@Json(name = "md5") val hash: String
|
||||
)
|
@ -1,8 +0,0 @@
|
||||
package com.topjohnwu.magisk.model.entity
|
||||
|
||||
import se.ansman.kotshi.JsonSerializable
|
||||
|
||||
@JsonSerializable
|
||||
data class MagiskLink(
|
||||
val link: String
|
||||
)
|
@ -0,0 +1,33 @@
|
||||
package com.topjohnwu.magisk.model.entity
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import se.ansman.kotshi.JsonSerializable
|
||||
|
||||
@JsonSerializable
|
||||
data class UpdateInfo(
|
||||
val app: ManagerJson = ManagerJson(),
|
||||
val uninstaller: UninstallerJson = UninstallerJson(),
|
||||
val magisk: MagiskJson = MagiskJson()
|
||||
)
|
||||
|
||||
@JsonSerializable
|
||||
data class UninstallerJson(
|
||||
val link: String = ""
|
||||
)
|
||||
|
||||
@JsonSerializable
|
||||
data class MagiskJson(
|
||||
val version: String = "",
|
||||
val versionCode: Int = -1,
|
||||
val link: String = "",
|
||||
val note: String = "",
|
||||
@Json(name = "md5") val hash: String = ""
|
||||
)
|
||||
|
||||
@JsonSerializable
|
||||
data class ManagerJson(
|
||||
val version: String = "",
|
||||
val versionCode: Int = -1,
|
||||
val link: String = "",
|
||||
val note: String = ""
|
||||
)
|
@ -73,7 +73,8 @@ open class GeneralReceiver : BroadcastReceiver() {
|
||||
}
|
||||
Intent.ACTION_LOCALE_CHANGED -> Shortcuts.setup(context)
|
||||
Const.Key.BROADCAST_MANAGER_UPDATE -> {
|
||||
Info.managerLink = intent.getStringExtra(Const.Key.INTENT_SET_LINK)
|
||||
Info.remote = Info.remote.copy(app = Info.remote.app.copy(
|
||||
link = intent.getStringExtra(Const.Key.INTENT_SET_LINK) ?: ""))
|
||||
DownloadApp.upgrade(intent.getStringExtra(Const.Key.INTENT_SET_NAME))
|
||||
}
|
||||
Const.Key.BROADCAST_REBOOT -> reboot()
|
||||
|
@ -18,9 +18,9 @@ class UpdateCheckService : DelegateWorker() {
|
||||
Shell.getShell()
|
||||
return runCatching {
|
||||
magiskRepo.fetchUpdate().blockingGet()
|
||||
if (BuildConfig.VERSION_CODE < Info.remoteManagerVersionCode)
|
||||
if (BuildConfig.VERSION_CODE < Info.remote.app.versionCode)
|
||||
Notifications.managerUpdate()
|
||||
else if (Info.magiskVersionCode < Info.remoteMagiskVersionCode)
|
||||
else if (Info.magiskVersionCode < Info.remote.magisk.versionCode)
|
||||
Notifications.magiskUpdate()
|
||||
ListenableWorker.Result.success()
|
||||
}.getOrElse {
|
||||
|
@ -123,9 +123,9 @@ public abstract class MagiskInstaller {
|
||||
|
||||
File zip = new File(App.self.getCacheDir(), "magisk.zip");
|
||||
|
||||
if (!ShellUtils.checkSum("MD5", zip, Info.magiskMD5)) {
|
||||
if (!ShellUtils.checkSum("MD5", zip, Info.remote.getMagisk().getHash())) {
|
||||
console.add("- Downloading zip");
|
||||
Networking.get(Info.magiskLink)
|
||||
Networking.get(Info.remote.getMagisk().getLink())
|
||||
.setDownloadProgressListener(new ProgressLog())
|
||||
.execForFile(zip);
|
||||
} else {
|
||||
|
@ -56,7 +56,7 @@ class HomeFragment : MagiskFragment<HomeViewModel, FragmentMagiskBinding>(),
|
||||
|
||||
private fun installMagisk() {
|
||||
// Show Manager update first
|
||||
if (Info.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
|
||||
if (Info.remote.app.versionCode > BuildConfig.VERSION_CODE) {
|
||||
installManager()
|
||||
return
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ class HomeViewModel(
|
||||
state = State.LOADED
|
||||
magiskState.value = when (Info.magiskVersionCode) {
|
||||
in Int.MIN_VALUE until 0 -> MagiskState.NOT_INSTALLED
|
||||
!in Info.remoteMagiskVersionCode..Int.MAX_VALUE -> MagiskState.OBSOLETE
|
||||
!in Info.remote.magisk.versionCode..Int.MAX_VALUE -> MagiskState.OBSOLETE
|
||||
else -> MagiskState.UP_TO_DATE
|
||||
}
|
||||
|
||||
@ -183,9 +183,9 @@ class HomeViewModel(
|
||||
}
|
||||
|
||||
magiskLatestVersion.value = version
|
||||
.format(Info.remoteMagiskVersionString, Info.remoteMagiskVersionCode)
|
||||
.format(Info.remote.magisk.version, Info.remote.magisk.versionCode)
|
||||
|
||||
managerState.value = when (Info.remoteManagerVersionCode) {
|
||||
managerState.value = when (Info.remote.app.versionCode) {
|
||||
in Int.MIN_VALUE until 0 -> MagiskState.NOT_INSTALLED //wrong update channel
|
||||
in (BuildConfig.VERSION_CODE + 1)..Int.MAX_VALUE -> MagiskState.OBSOLETE
|
||||
else -> MagiskState.UP_TO_DATE
|
||||
@ -195,7 +195,7 @@ class HomeViewModel(
|
||||
.format(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE)
|
||||
|
||||
managerLatestVersion.value = version
|
||||
.format(Info.remoteManagerVersionString, Info.remoteManagerVersionCode)
|
||||
.format(Info.remote.app.version, Info.remote.app.versionCode)
|
||||
}
|
||||
|
||||
private fun ensureEnv() {
|
||||
|
@ -26,7 +26,7 @@ public class DownloadApp {
|
||||
|
||||
public static void restore() {
|
||||
String name = Utils.INSTANCE.fmt("MagiskManager v%s(%d)",
|
||||
Info.remoteManagerVersionString, Info.remoteManagerVersionCode);
|
||||
Info.remote.getApp().getVersion(), Info.remote.getApp().getVersionCode());
|
||||
dlInstall(name, new RestoreManager());
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ public class DownloadApp {
|
||||
File apk = new File(App.self.getCacheDir(), "manager.apk");
|
||||
ProgressNotification progress = new ProgressNotification(name);
|
||||
listener.progress = progress;
|
||||
Networking.get(Info.managerLink)
|
||||
Networking.get(Info.remote.getApp().getLink())
|
||||
.setExecutor(App.THREAD_POOL)
|
||||
.setDownloadProgressListener(progress)
|
||||
.setErrorHandler((conn, e) -> progress.dlFail())
|
||||
|
@ -63,11 +63,11 @@ public class Notifications {
|
||||
public static void managerUpdate() {
|
||||
App app = App.self;
|
||||
String name = Utils.INSTANCE.fmt("MagiskManager v%s(%d)",
|
||||
Info.remoteManagerVersionString, Info.remoteManagerVersionCode);
|
||||
Info.remote.getApp().getVersion(), Info.remote.getApp().getVersionCode());
|
||||
|
||||
Intent intent = new Intent(app, ClassMap.get(GeneralReceiver.class));
|
||||
intent.setAction(Const.Key.BROADCAST_MANAGER_UPDATE);
|
||||
intent.putExtra(Const.Key.INTENT_SET_LINK, Info.managerLink);
|
||||
intent.putExtra(Const.Key.INTENT_SET_LINK, Info.remote.getApp().getLink());
|
||||
intent.putExtra(Const.Key.INTENT_SET_NAME, name);
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(app,
|
||||
Const.ID.APK_UPDATE_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
@ -57,11 +57,11 @@ internal class InstallMethodDialog(activity: MagiskActivity<*, *>, options: List
|
||||
private fun downloadOnly(activity: MagiskActivity<*, *>) {
|
||||
activity.withExternalRW {
|
||||
onSuccess {
|
||||
val filename = "Magisk-v${Info.remoteMagiskVersionString}" +
|
||||
"(${Info.remoteMagiskVersionCode}).zip"
|
||||
val filename = "Magisk-v${Info.remote.magisk.version}" +
|
||||
"(${Info.remote.magisk.versionCode}).zip"
|
||||
val zip = File(Const.EXTERNAL_PATH, filename)
|
||||
val progress = ProgressNotification(filename)
|
||||
Networking.get(Info.magiskLink)
|
||||
Networking.get(Info.remote.magisk.link)
|
||||
.setDownloadProgressListener(progress)
|
||||
.setErrorHandler { _, _ -> progress.dlFail() }
|
||||
.getAsFile(zip) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.topjohnwu.magisk.view.dialogs
|
||||
|
||||
import android.net.Uri
|
||||
import android.text.TextUtils
|
||||
import com.topjohnwu.magisk.Info
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.ui.base.MagiskActivity
|
||||
@ -13,8 +12,8 @@ import java.util.*
|
||||
|
||||
class MagiskInstallDialog(a: MagiskActivity<*, *>) : CustomAlertDialog(a) {
|
||||
init {
|
||||
val filename = "Magisk v${Info.remoteMagiskVersionString}" +
|
||||
"(${Info.remoteMagiskVersionCode})"
|
||||
val filename = "Magisk v${Info.remote.magisk.version}" +
|
||||
"(${Info.remote.magisk.versionCode})"
|
||||
setTitle(a.getString(R.string.repo_install_title, a.getString(R.string.magisk)))
|
||||
setMessage(a.getString(R.string.repo_install_msg, filename))
|
||||
setCancelable(true)
|
||||
@ -31,13 +30,13 @@ class MagiskInstallDialog(a: MagiskActivity<*, *>) : CustomAlertDialog(a) {
|
||||
}
|
||||
InstallMethodDialog(a, options).show()
|
||||
}
|
||||
if (!TextUtils.isEmpty(Info.magiskNoteLink)) {
|
||||
if (Info.remote.magisk.note.isNotEmpty()) {
|
||||
setNeutralButton(R.string.release_notes) { _, _ ->
|
||||
if (Info.magiskNoteLink.contains("forum.xda-developers")) {
|
||||
if (Info.remote.magisk.note.contains("forum.xda-developers")) {
|
||||
// Open forum links in browser
|
||||
Utils.openLink(a, Uri.parse(Info.magiskNoteLink))
|
||||
Utils.openLink(a, Uri.parse(Info.remote.magisk.note))
|
||||
} else {
|
||||
MarkDownWindow.show(a, null, Info.magiskNoteLink)
|
||||
MarkDownWindow.show(a, null, Info.remote.magisk.note)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,15 +9,15 @@ import com.topjohnwu.magisk.view.MarkDownWindow
|
||||
class ManagerInstallDialog(a: Activity) : CustomAlertDialog(a) {
|
||||
|
||||
init {
|
||||
val name = "MagiskManager v${Info.remoteManagerVersionString}" +
|
||||
"(${Info.remoteManagerVersionCode})"
|
||||
val name = "MagiskManager v${Info.remote.app.version}" +
|
||||
"(${Info.remote.app.versionCode})"
|
||||
setTitle(a.getString(R.string.repo_install_title, a.getString(R.string.app_name)))
|
||||
setMessage(a.getString(R.string.repo_install_msg, name))
|
||||
setCancelable(true)
|
||||
setPositiveButton(R.string.install) { _, _ -> DownloadApp.upgrade(name) }
|
||||
if (Info.managerNoteLink.isNotEmpty()) {
|
||||
if (Info.remote.app.note.isNotEmpty()) {
|
||||
setNeutralButton(R.string.app_changelog) { _, _ ->
|
||||
MarkDownWindow.show(a, null, Info.managerNoteLink) }
|
||||
MarkDownWindow.show(a, null, Info.remote.app.note) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,7 @@ import android.app.Activity
|
||||
import android.app.ProgressDialog
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.text.TextUtils
|
||||
import android.widget.Toast
|
||||
|
||||
import com.topjohnwu.magisk.ClassMap
|
||||
import com.topjohnwu.magisk.Const
|
||||
import com.topjohnwu.magisk.Info
|
||||
@ -16,7 +14,6 @@ import com.topjohnwu.magisk.utils.Utils
|
||||
import com.topjohnwu.magisk.view.ProgressNotification
|
||||
import com.topjohnwu.net.Networking
|
||||
import com.topjohnwu.superuser.Shell
|
||||
|
||||
import java.io.File
|
||||
|
||||
class UninstallDialog(activity: Activity) : CustomAlertDialog(activity) {
|
||||
@ -37,11 +34,11 @@ class UninstallDialog(activity: Activity) : CustomAlertDialog(activity) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!TextUtils.isEmpty(Info.uninstallerLink)) {
|
||||
if (Info.remote.uninstaller.link.isNotEmpty()) {
|
||||
setPositiveButton(R.string.complete_uninstall) { d, i ->
|
||||
val zip = File(activity.filesDir, "uninstaller.zip")
|
||||
val progress = ProgressNotification(zip.name)
|
||||
Networking.get(Info.uninstallerLink)
|
||||
Networking.get(Info.remote.uninstaller.link)
|
||||
.setDownloadProgressListener(progress)
|
||||
.setErrorHandler { _, _ -> progress.dlFail() }
|
||||
.getAsFile(zip) { f ->
|
||||
|
Loading…
x
Reference in New Issue
Block a user