mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 21:27:39 +00:00
Fix flow parallel
This commit is contained in:
parent
1e05f8c646
commit
b6affe06a5
@ -46,6 +46,14 @@ class DenyListViewModel : BaseViewModel(), Queryable {
|
|||||||
it.bindExtra(BR.viewModel, this)
|
it.bindExtra(BR.viewModel, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FlowPreview
|
||||||
|
private inline fun <T, R> Flow<T>.concurrentMap(crossinline transform: suspend (T) -> R): Flow<R> {
|
||||||
|
return flatMapMerge { value ->
|
||||||
|
flow { emit(transform(value)) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FlowPreview
|
||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
override fun refresh() = viewModelScope.launch {
|
override fun refresh() = viewModelScope.launch {
|
||||||
if (!Utils.showSuperUser()) {
|
if (!Utils.showSuperUser()) {
|
||||||
@ -53,18 +61,18 @@ class DenyListViewModel : BaseViewModel(), Queryable {
|
|||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
state = State.LOADING
|
state = State.LOADING
|
||||||
val (apps, diff) = withContext(Dispatchers.IO) {
|
val (apps, diff) = withContext(Dispatchers.Default) {
|
||||||
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).asFlow()
|
val apps = pm.getInstalledApplications(MATCH_UNINSTALLED_PACKAGES).run {
|
||||||
|
asFlow()
|
||||||
.filter { AppContext.packageName != it.packageName }
|
.filter { AppContext.packageName != it.packageName }
|
||||||
.map { async { AppProcessInfo(it, pm, denyList) } }
|
.concurrentMap { AppProcessInfo(it, pm, denyList) }
|
||||||
.map { it.await() }
|
|
||||||
.filter { it.processes.isNotEmpty() }
|
.filter { it.processes.isNotEmpty() }
|
||||||
.map { async { DenyListRvItem(it) } }
|
.concurrentMap { DenyListRvItem(it) }
|
||||||
.map { it.await() }
|
.toCollection(ArrayList(size))
|
||||||
.toCollection(ArrayList())
|
}
|
||||||
apps.sort()
|
apps.sort()
|
||||||
apps to items.calculateDiff(apps)
|
apps to items.calculateDiff(apps)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user