mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-01-11 18:53:37 +00:00
Updated downloading magisk to pull the zip from cache if eligible
This commit is contained in:
parent
4c8f357978
commit
188ea2644a
@ -15,9 +15,11 @@ import com.topjohnwu.magisk.utils.Utils
|
|||||||
import com.topjohnwu.magisk.view.ProgressNotification
|
import com.topjohnwu.magisk.view.ProgressNotification
|
||||||
import com.topjohnwu.magisk.view.SnackbarMaker
|
import com.topjohnwu.magisk.view.SnackbarMaker
|
||||||
import com.topjohnwu.net.Networking
|
import com.topjohnwu.net.Networking
|
||||||
|
import com.topjohnwu.superuser.ShellUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
internal class InstallMethodDialog(activity: MagiskActivity<*, *>, options: List<String>) : AlertDialog.Builder(activity) {
|
internal class InstallMethodDialog(activity: MagiskActivity<*, *>, options: List<String>) :
|
||||||
|
AlertDialog.Builder(activity) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setTitle(R.string.select_method)
|
setTitle(R.string.select_method)
|
||||||
@ -27,7 +29,7 @@ internal class InstallMethodDialog(activity: MagiskActivity<*, *>, options: List
|
|||||||
1 -> patchBoot(activity)
|
1 -> patchBoot(activity)
|
||||||
2 -> {
|
2 -> {
|
||||||
val intent = Intent(activity, ClassMap[FlashActivity::class.java])
|
val intent = Intent(activity, ClassMap[FlashActivity::class.java])
|
||||||
.putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK)
|
.putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK)
|
||||||
activity.startActivity(intent)
|
activity.startActivity(intent)
|
||||||
}
|
}
|
||||||
3 -> installInactiveSlot(activity)
|
3 -> installInactiveSlot(activity)
|
||||||
@ -40,13 +42,13 @@ internal class InstallMethodDialog(activity: MagiskActivity<*, *>, options: List
|
|||||||
onSuccess {
|
onSuccess {
|
||||||
Utils.toast(R.string.patch_file_msg, Toast.LENGTH_LONG)
|
Utils.toast(R.string.patch_file_msg, Toast.LENGTH_LONG)
|
||||||
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
||||||
.setType("*/*")
|
.setType("*/*")
|
||||||
.addCategory(Intent.CATEGORY_OPENABLE)
|
.addCategory(Intent.CATEGORY_OPENABLE)
|
||||||
activity.startActivityForResult(intent, Const.ID.SELECT_BOOT) { resultCode, data ->
|
activity.startActivityForResult(intent, Const.ID.SELECT_BOOT) { resultCode, data ->
|
||||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||||
val i = Intent(this, ClassMap[FlashActivity::class.java])
|
val i = Intent(this, ClassMap[FlashActivity::class.java])
|
||||||
.setData(data.data)
|
.setData(data.data)
|
||||||
.putExtra(Const.Key.FLASH_ACTION, Const.Value.PATCH_FILE)
|
.putExtra(Const.Key.FLASH_ACTION, Const.Value.PATCH_FILE)
|
||||||
startActivity(i)
|
startActivity(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,31 +62,45 @@ internal class InstallMethodDialog(activity: MagiskActivity<*, *>, options: List
|
|||||||
val filename = "Magisk-v${Info.remote.magisk.version}" +
|
val filename = "Magisk-v${Info.remote.magisk.version}" +
|
||||||
"(${Info.remote.magisk.versionCode}).zip"
|
"(${Info.remote.magisk.versionCode}).zip"
|
||||||
val zip = File(Const.EXTERNAL_PATH, filename)
|
val zip = File(Const.EXTERNAL_PATH, filename)
|
||||||
val progress = ProgressNotification(filename)
|
val cachedZip = File(activity.cacheDir, "magisk.zip")
|
||||||
Networking.get(Info.remote.magisk.link)
|
|
||||||
|
fun onSuccess() {
|
||||||
|
SnackbarMaker.make(
|
||||||
|
activity,
|
||||||
|
activity.getString(R.string.internal_storage, "/Download/$filename"),
|
||||||
|
Snackbar.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ShellUtils.checkSum("MD5", cachedZip, Info.remote.magisk.hash)) {
|
||||||
|
cachedZip.copyTo(zip, true)
|
||||||
|
onSuccess()
|
||||||
|
} else {
|
||||||
|
val progress = ProgressNotification(filename)
|
||||||
|
Networking.get(Info.remote.magisk.link)
|
||||||
.setDownloadProgressListener(progress)
|
.setDownloadProgressListener(progress)
|
||||||
.setErrorHandler { _, _ -> progress.dlFail() }
|
.setErrorHandler { _, _ -> progress.dlFail() }
|
||||||
.getAsFile(zip) {
|
.getAsFile(zip) {
|
||||||
progress.dlDone()
|
progress.dlDone()
|
||||||
SnackbarMaker.make(activity,
|
onSuccess()
|
||||||
activity.getString(R.string.internal_storage, "/Download/$filename"),
|
|
||||||
Snackbar.LENGTH_LONG).show()
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun installInactiveSlot(activity: MagiskActivity<*, *>) {
|
private fun installInactiveSlot(activity: MagiskActivity<*, *>) {
|
||||||
CustomAlertDialog(activity)
|
CustomAlertDialog(activity)
|
||||||
.setTitle(R.string.warning)
|
.setTitle(R.string.warning)
|
||||||
.setMessage(R.string.install_inactive_slot_msg)
|
.setMessage(R.string.install_inactive_slot_msg)
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setPositiveButton(R.string.yes) { _, _ ->
|
.setPositiveButton(R.string.yes) { _, _ ->
|
||||||
val intent = Intent(activity, ClassMap[FlashActivity::class.java])
|
val intent = Intent(activity, ClassMap[FlashActivity::class.java])
|
||||||
.putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_INACTIVE_SLOT)
|
.putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_INACTIVE_SLOT)
|
||||||
activity.startActivity(intent)
|
activity.startActivity(intent)
|
||||||
}
|
}
|
||||||
.setNegativeButton(R.string.no_thanks, null)
|
.setNegativeButton(R.string.no_thanks, null)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user