mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-30 13:35:27 +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.di.AppContext
|
||||||
import com.topjohnwu.magisk.utils.Utils
|
import com.topjohnwu.magisk.utils.Utils
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.withContext
|
import java.util.*
|
||||||
import java.util.stream.Collectors
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class DenyListViewModel : BaseViewModel(), Queryable {
|
class DenyListViewModel : BaseViewModel(), Queryable {
|
||||||
|
|
||||||
@ -55,17 +55,19 @@ class DenyListViewModel : BaseViewModel(), Queryable {
|
|||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
state = State.LOADING
|
state = State.LOADING
|
||||||
val (apps, diff) = withContext(Dispatchers.Default) {
|
val (apps, diff) = withContext(Dispatchers.IO) {
|
||||||
val pm = AppContext.packageManager
|
val pm = AppContext.packageManager
|
||||||
val denyList = Shell.su("magisk --denylist ls").exec().out
|
val denyList = Shell.su("magisk --denylist ls").exec().out
|
||||||
.map { CmdlineListItem(it) }
|
.map { CmdlineListItem(it) }
|
||||||
val apps = pm.getInstalledApplications(MATCH_UNINSTALLED_PACKAGES).parallelStream()
|
val apps = pm.getInstalledApplications(MATCH_UNINSTALLED_PACKAGES).asFlow()
|
||||||
.filter { AppContext.packageName != it.packageName }
|
.filter { AppContext.packageName != it.packageName }
|
||||||
.map { AppProcessInfo(it, pm, denyList) }
|
.map { async { AppProcessInfo(it, pm, denyList) } }
|
||||||
|
.map { it.await() }
|
||||||
.filter { it.processes.isNotEmpty() }
|
.filter { it.processes.isNotEmpty() }
|
||||||
.map { DenyListRvItem(it) }
|
.map { async { DenyListRvItem(it) } }
|
||||||
.sorted()
|
.map { it.await() }
|
||||||
.collect(Collectors.toList())
|
.toCollection(ArrayList())
|
||||||
|
apps.sort()
|
||||||
apps to items.calculateDiff(apps)
|
apps to items.calculateDiff(apps)
|
||||||
}
|
}
|
||||||
items.update(apps, diff)
|
items.update(apps, diff)
|
||||||
|
Loading…
Reference in New Issue
Block a user