mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-01-12 00:23:37 +00:00
Prevent multiple installation sessions running in parallel
This commit is contained in:
parent
9164bf22c2
commit
803982a271
@ -43,6 +43,8 @@ import java.security.SecureRandom
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
|
|
||||||
|
private var haveActiveSession: Boolean = false
|
||||||
|
|
||||||
abstract class MagiskInstallImpl protected constructor(
|
abstract class MagiskInstallImpl protected constructor(
|
||||||
protected val console: MutableList<String> = NOPList.getInstance(),
|
protected val console: MutableList<String> = NOPList.getInstance(),
|
||||||
private val logs: MutableList<String> = NOPList.getInstance()
|
private val logs: MutableList<String> = NOPList.getInstance()
|
||||||
@ -415,7 +417,18 @@ abstract class MagiskInstallImpl protected constructor(
|
|||||||
@WorkerThread
|
@WorkerThread
|
||||||
protected abstract suspend fun operations(): Boolean
|
protected abstract suspend fun operations(): Boolean
|
||||||
|
|
||||||
open suspend fun exec() = withContext(Dispatchers.IO) { operations() }
|
open suspend fun exec(): Boolean {
|
||||||
|
synchronized(haveActiveSession) {
|
||||||
|
if (haveActiveSession)
|
||||||
|
return false
|
||||||
|
haveActiveSession = true
|
||||||
|
}
|
||||||
|
val result = withContext(Dispatchers.IO) { operations() }
|
||||||
|
synchronized(haveActiveSession) {
|
||||||
|
haveActiveSession = false
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class MagiskInstaller(
|
abstract class MagiskInstaller(
|
||||||
|
@ -50,6 +50,7 @@ class FlashFragment : BaseUIFragment<FlashViewModel, FragmentFlashMd2Binding>()
|
|||||||
|
|
||||||
defaultOrientation = activity.requestedOrientation
|
defaultOrientation = activity.requestedOrientation
|
||||||
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR
|
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR
|
||||||
|
viewModel.startFlashing()
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("WrongConstant")
|
@SuppressLint("WrongConstant")
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.topjohnwu.magisk.ui.flash
|
package com.topjohnwu.magisk.ui.flash
|
||||||
|
|
||||||
import android.net.Uri
|
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import androidx.databinding.Bindable
|
import androidx.databinding.Bindable
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
@ -27,7 +26,7 @@ import com.topjohnwu.superuser.Shell
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class FlashViewModel(args: FlashFragmentArgs) : BaseViewModel() {
|
class FlashViewModel(private val args: FlashFragmentArgs) : BaseViewModel() {
|
||||||
|
|
||||||
@get:Bindable
|
@get:Bindable
|
||||||
var showReboot = Shell.rootAccess()
|
var showReboot = Shell.rootAccess()
|
||||||
@ -49,14 +48,11 @@ class FlashViewModel(args: FlashFragmentArgs) : BaseViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
fun startFlashing() {
|
||||||
val (action, uri, id) = args
|
val (action, uri, id) = args
|
||||||
if (id != -1)
|
if (id != -1)
|
||||||
Notifications.mgr.cancel(id)
|
Notifications.mgr.cancel(id)
|
||||||
startFlashing(action, uri)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun startFlashing(action: String, uri: Uri?) {
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val result = when (action) {
|
val result = when (action) {
|
||||||
Const.Value.FLASH_ZIP -> {
|
Const.Value.FLASH_ZIP -> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user