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

View File

@ -14,8 +14,8 @@ import com.topjohnwu.magisk.Const
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.data.repository.FileRepository
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.toast
import com.topjohnwu.magisk.utils.writeToCachedFile
import com.topjohnwu.magisk.view.Notifications
import com.topjohnwu.superuser.ShellUtils
@ -98,7 +98,10 @@ abstract class SubstrateDownloadService : Service() {
destination.deleteRecursively()
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 {
@Parcelize
object Flash : Configuration()
sealed class Flash : Configuration() {
@Parcelize
object Primary : Flash()
@Parcelize
object Secondary : Flash()
}
@Parcelize
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, 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 */
fun flashIntent(context: Context, file: File) = intent(context, file)
.putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK)
fun flashIntent(context: Context, file: File, isSecondSlot: Boolean) = intent(context, file)
.putExtra(Const.Key.FLASH_ACTION, flashType(isSecondSlot))
fun flash(context: Context, file: File) =
context.startActivity(flashIntent(context, file))
fun flash(context: Context, file: File, isSecondSlot: Boolean) =
context.startActivity(flashIntent(context, file, isSecondSlot))
/* Patching is understood as injecting img files with magisk */