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 package com.topjohnwu.magisk.model.download
import android.Manifest
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
import android.webkit.MimeTypeMap import android.webkit.MimeTypeMap
import androidx.annotation.RequiresPermission
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import com.topjohnwu.magisk.ClassMap import com.topjohnwu.magisk.ClassMap
import com.topjohnwu.magisk.R import com.topjohnwu.magisk.R
@ -115,7 +113,6 @@ open class DownloadService : RemoteFileService() {
companion object { companion object {
@RequiresPermission(allOf = [Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE])
inline operator fun invoke(context: Context, argBuilder: Builder.() -> Unit) { inline operator fun invoke(context: Context, argBuilder: Builder.() -> Unit) {
val builder = Builder().apply(argBuilder) val builder = Builder().apply(argBuilder)
val intent = Intent(context, ClassMap[DownloadService::class.java]) 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 @Parcelize
protected class Download : Magisk() { protected class Download : Magisk() {
override val configuration: Configuration get() = Configuration.Download override val configuration: Configuration get() = Configuration.Download
@ -63,6 +74,7 @@ sealed class DownloadSubject : Parcelable {
companion object { companion object {
operator fun invoke(configuration: Configuration) = when (configuration) { operator fun invoke(configuration: Configuration) = when (configuration) {
Configuration.Download -> Download() Configuration.Download -> Download()
Configuration.Uninstall -> Uninstall()
else -> Flash(configuration) else -> Flash(configuration)
} }
} }

View File

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

View File

@ -2,19 +2,14 @@ package com.topjohnwu.magisk.view.dialogs
import android.app.Activity import android.app.Activity
import android.app.ProgressDialog import android.app.ProgressDialog
import android.content.Intent
import android.net.Uri
import android.widget.Toast import android.widget.Toast
import com.topjohnwu.magisk.ClassMap
import com.topjohnwu.magisk.Const
import com.topjohnwu.magisk.Info import com.topjohnwu.magisk.Info
import com.topjohnwu.magisk.R 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.utils.Utils
import com.topjohnwu.magisk.view.ProgressNotification
import com.topjohnwu.net.Networking
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import java.io.File
class UninstallDialog(activity: Activity) : CustomAlertDialog(activity) { class UninstallDialog(activity: Activity) : CustomAlertDialog(activity) {
@ -35,20 +30,10 @@ class UninstallDialog(activity: Activity) : CustomAlertDialog(activity) {
} }
} }
if (Info.remote.uninstaller.link.isNotEmpty()) { if (Info.remote.uninstaller.link.isNotEmpty()) {
setPositiveButton(R.string.complete_uninstall) { d, i -> setPositiveButton(R.string.complete_uninstall) { _, _ ->
val zip = File(activity.filesDir, "uninstaller.zip") DownloadService(activity) {
val progress = ProgressNotification(zip.name) subject = DownloadSubject.Magisk(Configuration.Uninstall)
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)
}
} }
} }
} }