diff --git a/app/src/main/java/com/topjohnwu/magisk/Info.java b/app/src/main/java/com/topjohnwu/magisk/Info.java index 338a10d85..1d9a1b1db 100644 --- a/app/src/main/java/com/topjohnwu/magisk/Info.java +++ b/app/src/main/java/com/topjohnwu/magisk/Info.java @@ -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; diff --git a/app/src/main/java/com/topjohnwu/magisk/data/network/GithubRawApiServices.kt b/app/src/main/java/com/topjohnwu/magisk/data/network/GithubRawApiServices.kt index 262bab4ce..7663fb839 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/network/GithubRawApiServices.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/network/GithubRawApiServices.kt @@ -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 + fun fetchStableUpdate(): Single @GET("$MAGISK_FILES/master/beta.json") - fun fetchBetaUpdate(): Single + fun fetchBetaUpdate(): Single @GET("$MAGISK_FILES/master/canary_builds/release.json") - fun fetchCanaryUpdate(): Single + fun fetchCanaryUpdate(): Single @GET("$MAGISK_FILES/master/canary_builds/canary.json") - fun fetchCanaryDebugUpdate(): Single + fun fetchCanaryDebugUpdate(): Single @GET - fun fetchCustomUpdate(@Url url: String): Single + fun fetchCustomUpdate(@Url url: String): Single @GET("$MAGISK_FILES/{$REVISION}/snet.apk") @Streaming diff --git a/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt b/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt index 88549261a..cc65d0f5f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt @@ -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) } diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskApp.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskApp.kt deleted file mode 100644 index fb9c4f7ff..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskApp.kt +++ /dev/null @@ -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 -) \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskConfig.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskConfig.kt deleted file mode 100644 index 4983dabbe..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskConfig.kt +++ /dev/null @@ -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 -) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskFlashable.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskFlashable.kt deleted file mode 100644 index a9b3ce04b..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskFlashable.kt +++ /dev/null @@ -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 -) \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskLink.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskLink.kt deleted file mode 100644 index 599dfb8ad..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskLink.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.topjohnwu.magisk.model.entity - -import se.ansman.kotshi.JsonSerializable - -@JsonSerializable -data class MagiskLink( - val link: String -) \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/UpdateInfo.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/UpdateInfo.kt new file mode 100644 index 000000000..ed80529b0 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/UpdateInfo.kt @@ -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 = "" +) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt b/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt index 636858e6a..0fd552cf8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt @@ -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() diff --git a/app/src/main/java/com/topjohnwu/magisk/model/update/UpdateCheckService.kt b/app/src/main/java/com/topjohnwu/magisk/model/update/UpdateCheckService.kt index 4792bb133..8740ec7fe 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/update/UpdateCheckService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/update/UpdateCheckService.kt @@ -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 { diff --git a/app/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java b/app/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java index cc867b1bd..197125158 100644 --- a/app/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java +++ b/app/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java @@ -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 { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt index 146bad9df..200e9d8a7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt @@ -56,7 +56,7 @@ class HomeFragment : MagiskFragment(), private fun installMagisk() { // Show Manager update first - if (Info.remoteManagerVersionCode > BuildConfig.VERSION_CODE) { + if (Info.remote.app.versionCode > BuildConfig.VERSION_CODE) { installManager() return } 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 ae429b6d3..87648c825 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 @@ -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() { diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/DownloadApp.java b/app/src/main/java/com/topjohnwu/magisk/utils/DownloadApp.java index f984ade12..c6547df18 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/DownloadApp.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/DownloadApp.java @@ -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()) diff --git a/app/src/main/java/com/topjohnwu/magisk/view/Notifications.java b/app/src/main/java/com/topjohnwu/magisk/view/Notifications.java index 3b01372bb..9cd0eac4a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/view/Notifications.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/Notifications.java @@ -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); diff --git a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/InstallMethodDialog.kt b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/InstallMethodDialog.kt index b6f649ea6..1cc63c6d3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/InstallMethodDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/InstallMethodDialog.kt @@ -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) { diff --git a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/MagiskInstallDialog.kt b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/MagiskInstallDialog.kt index 395ff1938..54059b3ab 100644 --- a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/MagiskInstallDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/MagiskInstallDialog.kt @@ -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) } } } diff --git a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/ManagerInstallDialog.kt b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/ManagerInstallDialog.kt index db5a2250e..1c6612dba 100644 --- a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/ManagerInstallDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/ManagerInstallDialog.kt @@ -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) } } } } diff --git a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/UninstallDialog.kt b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/UninstallDialog.kt index e49698c1d..fe474bb2b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/UninstallDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/UninstallDialog.kt @@ -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 ->