From 468796c23dca65dc4633059205f80ccdeeb90e35 Mon Sep 17 00:00:00 2001 From: vvb2060 Date: Fri, 16 Oct 2020 17:23:49 +0800 Subject: [PATCH] Add option to show OS apps --- .../topjohnwu/magisk/ui/hide/HideViewModel.kt | 24 ++++++++++++------- .../main/res/layout/include_hide_filter.xml | 18 ++++++++++++-- app/src/main/res/values/strings.xml | 1 + 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideViewModel.kt index 7264f913e..cf8f51745 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideViewModel.kt @@ -1,5 +1,6 @@ package com.topjohnwu.magisk.ui.hide +import android.annotation.SuppressLint import android.content.pm.ApplicationInfo import android.content.pm.PackageManager import androidx.databinding.Bindable @@ -27,14 +28,20 @@ class HideViewModel : BaseViewModel(), Queryable { @get:Bindable var isShowSystem = Config.showSystemApp - set(value) = set(value, field, { field = it }, BR.showSystem){ + set(value) = set(value, field, { field = it }, BR.showSystem) { Config.showSystemApp = it submitQuery() } + @get:Bindable + var isShowOS = false + set(value) = set(value, field, { field = it }, BR.showOS) { + submitQuery() + } + @get:Bindable var query = "" - set(value) = set(value, field, { field = it }, BR.query){ + set(value) = set(value, field, { field = it }, BR.query) { submitQuery() } @@ -46,6 +53,7 @@ class HideViewModel : BaseViewModel(), Queryable { it.bindExtra(BR.viewModel, this) } + @SuppressLint("InlinedApi") override fun refresh() = viewModelScope.launch { if (!Utils.showSuperUser()) { state = State.LOADING_FAILED @@ -55,9 +63,9 @@ class HideViewModel : BaseViewModel(), Queryable { val (apps, diff) = withContext(Dispatchers.Default) { val pm = get() val hides = Shell.su("magiskhide --ls").exec().out.map { HideTarget(it) } - val apps = pm.getInstalledApplications(0) + val apps = pm.getInstalledApplications(PackageManager.MATCH_UNINSTALLED_PACKAGES) .asSequence() - .filter { it.enabled && it.uid >= 10000 && !blacklist.contains(it.packageName) } + .filter { it.enabled && !blacklist.contains(it.packageName) } .map { HideAppInfo(it, pm) } .map { createTarget(it, hides) } .filter { it.processes.isNotEmpty() } @@ -88,8 +96,9 @@ class HideViewModel : BaseViewModel(), Queryable { items.filter { fun showHidden() = it.itemsChecked != 0 - fun filterSystem() = - isShowSystem || it.info.flags and ApplicationInfo.FLAG_SYSTEM == 0 + fun filterSystem() = isShowSystem || it.info.flags and ApplicationInfo.FLAG_SYSTEM == 0 + + fun filterOS() = (isShowSystem && isShowOS) || it.info.uid >= 10000 fun filterQuery(): Boolean { fun inName() = it.info.label.contains(query, true) @@ -98,7 +107,7 @@ class HideViewModel : BaseViewModel(), Queryable { return inName() || inPackage() || inProcesses() } - showHidden() || (filterSystem() && filterQuery()) + showHidden() || (filterSystem() && filterOS() && filterQuery()) } state = State.LOADED } @@ -121,4 +130,3 @@ class HideViewModel : BaseViewModel(), Queryable { ) } } } - diff --git a/app/src/main/res/layout/include_hide_filter.xml b/app/src/main/res/layout/include_hide_filter.xml index 82f5b7265..f7c04b7ee 100644 --- a/app/src/main/res/layout/include_hide_filter.xml +++ b/app/src/main/res/layout/include_hide_filter.xml @@ -47,7 +47,7 @@ app:layout_constraintTop_toBottomOf="@+id/hide_filter_title_filter"> + + Show system apps + Show OS apps Filter by name Scroll up Filters