Use new service to download uninstall.zip

This commit is contained in:
topjohnwu 2019-07-25 03:10:24 -07:00
parent c3a89f589e
commit 0aebc0a8e3
4 changed files with 21 additions and 36 deletions

View File

@ -1,13 +1,11 @@
package com.topjohnwu.magisk.model.download
import android.Manifest
import android.annotation.SuppressLint
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import android.webkit.MimeTypeMap
import androidx.annotation.RequiresPermission
import androidx.core.app.NotificationCompat
import com.topjohnwu.magisk.ClassMap
import com.topjohnwu.magisk.R
@ -115,7 +113,6 @@ open class DownloadService : RemoteFileService() {
companion object {
@RequiresPermission(allOf = [Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE])
inline operator fun invoke(context: Context, argBuilder: Builder.() -> Unit) {
val builder = Builder().apply(argBuilder)
val intent = Intent(context, ClassMap[DownloadService::class.java])

View File

@ -49,6 +49,17 @@ sealed class DownloadSubject : Parcelable {
}
}
@Parcelize
protected class Uninstall : Magisk() {
override val configuration: Configuration get() = Configuration.Uninstall
override val url: String get() = Info.remote.uninstaller.link
@IgnoredOnParcel
override val file by lazy {
get<Context>().cachedFile("uninstall.zip")
}
}
@Parcelize
protected class Download : Magisk() {
override val configuration: Configuration get() = Configuration.Download
@ -63,6 +74,7 @@ sealed class DownloadSubject : Parcelable {
companion object {
operator fun invoke(configuration: Configuration) = when (configuration) {
Configuration.Download -> Download()
Configuration.Uninstall -> Uninstall()
else -> Flash(configuration)
}
}

View File

@ -1,6 +1,5 @@
package com.topjohnwu.magisk.view.dialogs
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.net.Uri
@ -29,16 +28,10 @@ internal class InstallMethodDialog(activity: MagiskActivity<*, *>, options: List
}
}
@SuppressLint("MissingPermission")
private fun flash(activity: MagiskActivity<*, *>) = activity.withExternalRW {
onSuccess {
DownloadService(context) {
private fun flash(activity: MagiskActivity<*, *>) = DownloadService(activity) {
subject = DownloadSubject.Magisk(Configuration.Flash.Primary)
}
}
}
@SuppressLint("MissingPermission")
private fun patchBoot(activity: MagiskActivity<*, *>) = activity.withExternalRW {
onSuccess {
Utils.toast(R.string.patch_file_msg, Toast.LENGTH_LONG)
@ -56,7 +49,6 @@ internal class InstallMethodDialog(activity: MagiskActivity<*, *>, options: List
}
}
@SuppressLint("MissingPermission")
private fun downloadOnly(activity: MagiskActivity<*, *>) = activity.withExternalRW {
onSuccess {
DownloadService(activity) {
@ -65,7 +57,6 @@ internal class InstallMethodDialog(activity: MagiskActivity<*, *>, options: List
}
}
@SuppressLint("MissingPermission")
private fun installInactiveSlot(activity: MagiskActivity<*, *>) {
CustomAlertDialog(activity)
.setTitle(R.string.warning)

View File

@ -2,19 +2,14 @@ package com.topjohnwu.magisk.view.dialogs
import android.app.Activity
import android.app.ProgressDialog
import android.content.Intent
import android.net.Uri
import android.widget.Toast
import com.topjohnwu.magisk.ClassMap
import com.topjohnwu.magisk.Const
import com.topjohnwu.magisk.Info
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.ui.flash.FlashActivity
import com.topjohnwu.magisk.model.download.DownloadService
import com.topjohnwu.magisk.model.entity.internal.Configuration
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
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) {
@ -35,19 +30,9 @@ class UninstallDialog(activity: Activity) : CustomAlertDialog(activity) {
}
}
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.remote.uninstaller.link)
.setDownloadProgressListener(progress)
.setErrorHandler { _, _ -> progress.dlFail() }
.getAsFile(zip) { f ->
progress.dismiss()
val intent = Intent(activity, ClassMap[FlashActivity::class.java])
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setData(Uri.fromFile(f))
.putExtra(Const.Key.FLASH_ACTION, Const.Value.UNINSTALL)
activity.startActivity(intent)
setPositiveButton(R.string.complete_uninstall) { _, _ ->
DownloadService(activity) {
subject = DownloadSubject.Magisk(Configuration.Uninstall)
}
}
}