Added second slot flashing capability

This commit is contained in:
Viktor De Pasquale 2019-07-10 18:45:34 +02:00 committed by John Wu
parent 501b18f986
commit 1d16d980b3
4 changed files with 45 additions and 30 deletions

View File

@ -8,8 +8,11 @@ import android.content.Intent
import androidx.annotation.RequiresPermission 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.model.entity.internal.Configuration import com.topjohnwu.magisk.model.entity.internal.Configuration.*
import com.topjohnwu.magisk.model.entity.internal.Configuration.Flash.Secondary
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject.Magisk
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject.Module
import com.topjohnwu.magisk.ui.flash.FlashActivity import com.topjohnwu.magisk.ui.flash.FlashActivity
import java.io.File import java.io.File
import kotlin.random.Random.Default.nextInt import kotlin.random.Random.Default.nextInt
@ -20,27 +23,27 @@ open class CompoundDownloadService : SubstrateDownloadService() {
private val context get() = this private val context get() = this
override fun onFinished(file: File, subject: DownloadSubject) = when (subject) { override fun onFinished(file: File, subject: DownloadSubject) = when (subject) {
is DownloadSubject.Magisk -> onFinishedInternal(file, subject) is Magisk -> onFinishedInternal(file, subject)
is DownloadSubject.Module -> onFinishedInternal(file, subject) is Module -> onFinishedInternal(file, subject)
} }
private fun onFinishedInternal( private fun onFinishedInternal(
file: File, file: File,
subject: DownloadSubject.Magisk subject: Magisk
) = when (val conf = subject.configuration) { ) = when (val conf = subject.configuration) {
Configuration.Download -> moveToDownloads(file) Download -> moveToDownloads(file)
Configuration.Flash -> FlashActivity.flash(this, file) Uninstall -> FlashActivity.uninstall(this, file)
Configuration.Uninstall -> FlashActivity.uninstall(this, file) is Patch -> FlashActivity.patch(this, file, conf.fileUri)
is Configuration.Patch -> FlashActivity.patch(this, file, conf.fileUri) is Flash -> FlashActivity.flash(this, file, conf is Secondary)
else -> Unit else -> Unit
} }
private fun onFinishedInternal( private fun onFinishedInternal(
file: File, file: File,
subject: DownloadSubject.Module subject: Module
) = when (subject.configuration) { ) = when (subject.configuration) {
Configuration.Download -> moveToDownloads(file) Download -> moveToDownloads(file)
Configuration.Flash -> FlashActivity.install(this, file) is Flash -> FlashActivity.install(this, file)
else -> Unit else -> Unit
} }
@ -50,28 +53,27 @@ open class CompoundDownloadService : SubstrateDownloadService() {
file: File, file: File,
subject: DownloadSubject subject: DownloadSubject
) = when (subject) { ) = when (subject) {
is DownloadSubject.Magisk -> addActionsInternal(file, subject) is Magisk -> addActionsInternal(file, subject)
is DownloadSubject.Module -> addActionsInternal(file, subject) is Module -> addActionsInternal(file, subject)
} }
private fun NotificationCompat.Builder.addActionsInternal( private fun NotificationCompat.Builder.addActionsInternal(
file: File, file: File,
subject: DownloadSubject.Magisk subject: Magisk
) = when (val conf = subject.configuration) { ) = when (val conf = subject.configuration) {
Configuration.Download -> setContentIntent(fileIntent(subject.fileName)) Download -> setContentIntent(fileIntent(subject.fileName))
Configuration.Flash -> setContentIntent(FlashActivity.flashIntent(context, file)) Uninstall -> setContentIntent(FlashActivity.uninstallIntent(context, file))
Configuration.Uninstall -> setContentIntent(FlashActivity.uninstallIntent(context, file)) is Flash -> setContentIntent(FlashActivity.flashIntent(context, file, conf is Secondary))
is Configuration.Patch -> is Patch -> setContentIntent(FlashActivity.patchIntent(context, file, conf.fileUri))
setContentIntent(FlashActivity.patchIntent(context, file, conf.fileUri))
else -> this else -> this
} }
private fun NotificationCompat.Builder.addActionsInternal( private fun NotificationCompat.Builder.addActionsInternal(
file: File, file: File,
subject: DownloadSubject.Module subject: Module
) = when (subject.configuration) { ) = when (subject.configuration) {
Configuration.Download -> setContentIntent(fileIntent(subject.fileName)) Download -> setContentIntent(fileIntent(subject.fileName))
Configuration.Flash -> setContentIntent(FlashActivity.installIntent(context, file)) is Flash -> setContentIntent(FlashActivity.installIntent(context, file))
else -> this else -> this
} }

View File

@ -14,8 +14,8 @@ import com.topjohnwu.magisk.Const
import com.topjohnwu.magisk.R import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.data.repository.FileRepository import com.topjohnwu.magisk.data.repository.FileRepository
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import com.topjohnwu.magisk.utils.Utils
import com.topjohnwu.magisk.utils.provide import com.topjohnwu.magisk.utils.provide
import com.topjohnwu.magisk.utils.toast
import com.topjohnwu.magisk.utils.writeToCachedFile import com.topjohnwu.magisk.utils.writeToCachedFile
import com.topjohnwu.magisk.view.Notifications import com.topjohnwu.magisk.view.Notifications
import com.topjohnwu.superuser.ShellUtils import com.topjohnwu.superuser.ShellUtils
@ -98,7 +98,10 @@ abstract class SubstrateDownloadService : Service() {
destination.deleteRecursively() destination.deleteRecursively()
file.copyTo(destination) file.copyTo(destination)
} }
toast(getString(R.string.internal_storage, "/Download/${file.name}"), Toast.LENGTH_LONG) Utils.toast(
getString(R.string.internal_storage, "/Download/${file.name}"),
Toast.LENGTH_LONG
)
} }
// --- // ---

View File

@ -6,8 +6,15 @@ import kotlinx.android.parcel.Parcelize
sealed class Configuration : Parcelable { sealed class Configuration : Parcelable {
sealed class Flash : Configuration() {
@Parcelize @Parcelize
object Flash : Configuration() object Primary : Flash()
@Parcelize
object Secondary : Flash()
}
@Parcelize @Parcelize
object Download : Configuration() object Download : Configuration()

View File

@ -33,13 +33,16 @@ open class FlashActivity : MagiskActivity<FlashViewModel, ActivityFlashBinding>(
private fun intent(context: Context) = Intent(context, ClassMap[FlashActivity::class.java]) private fun intent(context: Context) = Intent(context, ClassMap[FlashActivity::class.java])
private fun intent(context: Context, file: File) = intent(context).setData(file.toUri()) private fun intent(context: Context, file: File) = intent(context).setData(file.toUri())
private fun flashType(isSecondSlot: Boolean) =
if (isSecondSlot) Const.Value.FLASH_INACTIVE_SLOT else Const.Value.FLASH_MAGISK
/* Flashing is understood as installing / flashing magisk itself */ /* Flashing is understood as installing / flashing magisk itself */
fun flashIntent(context: Context, file: File) = intent(context, file) fun flashIntent(context: Context, file: File, isSecondSlot: Boolean) = intent(context, file)
.putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK) .putExtra(Const.Key.FLASH_ACTION, flashType(isSecondSlot))
fun flash(context: Context, file: File) = fun flash(context: Context, file: File, isSecondSlot: Boolean) =
context.startActivity(flashIntent(context, file)) context.startActivity(flashIntent(context, file, isSecondSlot))
/* Patching is understood as injecting img files with magisk */ /* Patching is understood as injecting img files with magisk */