From 0aebc0a8e3457259abddaf02b72d0ce6bad70dba Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 25 Jul 2019 03:10:24 -0700 Subject: [PATCH] Use new service to download uninstall.zip --- .../magisk/model/download/DownloadService.kt | 3 -- .../model/entity/internal/DownloadSubject.kt | 12 ++++++++ .../view/dialogs/InstallMethodDialog.kt | 13 ++------- .../magisk/view/dialogs/UninstallDialog.kt | 29 +++++-------------- 4 files changed, 21 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt b/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt index fa0df28b9..f3ccce9b8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt @@ -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]) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt index 1a72f6672..44f420414 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt @@ -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().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) } } 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 b003008fa..f2be2764f 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 @@ -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) { - subject = DownloadSubject.Magisk(Configuration.Flash.Primary) - } - } + 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) 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 fe474bb2b..8c7244172 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 @@ -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,20 +30,10 @@ 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) + } } } }