mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-28 21:17:38 +00:00
Use Kotlin coroutine instead of Java parallelStream
This commit is contained in:
parent
6723d20616
commit
a3695cc66b
@ -13,10 +13,10 @@ import com.topjohnwu.magisk.databinding.itemBindingOf
|
||||
import com.topjohnwu.magisk.di.AppContext
|
||||
import com.topjohnwu.magisk.utils.Utils
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.stream.Collectors
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class DenyListViewModel : BaseViewModel(), Queryable {
|
||||
|
||||
@ -55,17 +55,19 @@ class DenyListViewModel : BaseViewModel(), Queryable {
|
||||
return@launch
|
||||
}
|
||||
state = State.LOADING
|
||||
val (apps, diff) = withContext(Dispatchers.Default) {
|
||||
val (apps, diff) = withContext(Dispatchers.IO) {
|
||||
val pm = AppContext.packageManager
|
||||
val denyList = Shell.su("magisk --denylist ls").exec().out
|
||||
.map { CmdlineListItem(it) }
|
||||
val apps = pm.getInstalledApplications(MATCH_UNINSTALLED_PACKAGES).parallelStream()
|
||||
val apps = pm.getInstalledApplications(MATCH_UNINSTALLED_PACKAGES).asFlow()
|
||||
.filter { AppContext.packageName != it.packageName }
|
||||
.map { AppProcessInfo(it, pm, denyList) }
|
||||
.map { async { AppProcessInfo(it, pm, denyList) } }
|
||||
.map { it.await() }
|
||||
.filter { it.processes.isNotEmpty() }
|
||||
.map { DenyListRvItem(it) }
|
||||
.sorted()
|
||||
.collect(Collectors.toList())
|
||||
.map { async { DenyListRvItem(it) } }
|
||||
.map { it.await() }
|
||||
.toCollection(ArrayList())
|
||||
apps.sort()
|
||||
apps to items.calculateDiff(apps)
|
||||
}
|
||||
items.update(apps, diff)
|
||||
|
Loading…
x
Reference in New Issue
Block a user