Commit e9759a58 authored by vvb2060's avatar vvb2060 Committed by John Wu

Update HideViewModel

parent e7ab8024
package com.topjohnwu.magisk.ktx package com.topjohnwu.magisk.ktx
import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.content.ComponentName import android.content.ComponentName
import android.content.Context import android.content.Context
...@@ -7,7 +8,6 @@ import android.content.ContextWrapper ...@@ -7,7 +8,6 @@ import android.content.ContextWrapper
import android.content.Intent import android.content.Intent
import android.content.pm.ApplicationInfo import android.content.pm.ApplicationInfo
import android.content.pm.ComponentInfo import android.content.pm.ComponentInfo
import android.content.pm.PackageInfo
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.pm.PackageManager.* import android.content.pm.PackageManager.*
import android.content.res.Configuration import android.content.res.Configuration
...@@ -57,29 +57,31 @@ import java.lang.reflect.Array as JArray ...@@ -57,29 +57,31 @@ import java.lang.reflect.Array as JArray
val packageName: String get() = get<Context>().packageName val packageName: String get() = get<Context>().packageName
val PackageInfo.processes val ApplicationInfo.processes: List<String> @SuppressLint("InlinedApi") get() {
get() = activities?.processNames.orEmpty() +
services?.processNames.orEmpty() +
receivers?.processNames.orEmpty() +
providers?.processNames.orEmpty()
val Array<out ComponentInfo>.processNames get() = mapNotNull { it.processName }
val ApplicationInfo.packageInfo: PackageInfo get() {
val pm = get<PackageManager>() val pm = get<PackageManager>()
val appProcessName = processName ?: packageName
return try { val baseFlag = MATCH_DISABLED_COMPONENTS or MATCH_UNINSTALLED_PACKAGES
val packageInfo = try {
val request = GET_ACTIVITIES or GET_SERVICES or GET_RECEIVERS or GET_PROVIDERS val request = GET_ACTIVITIES or GET_SERVICES or GET_RECEIVERS or GET_PROVIDERS
pm.getPackageInfo(packageName, request) pm.getPackageInfo(packageName, baseFlag or request)
} catch (e: NameNotFoundException) { // EdXposed hooked, issue#3276
return listOf(appProcessName)
} catch (e: Exception) { } catch (e: Exception) {
// Exceed binder data transfer limit, fetch each component type separately // Exceed binder data transfer limit, fetch each component type separately
pm.getPackageInfo(packageName, 0).apply { pm.getPackageInfo(packageName, baseFlag).apply {
runCatching { activities = pm.getPackageInfo(packageName, GET_ACTIVITIES).activities } runCatching { activities = pm.getPackageInfo(packageName, GET_ACTIVITIES).activities }
runCatching { services = pm.getPackageInfo(packageName, GET_SERVICES).services } runCatching { services = pm.getPackageInfo(packageName, GET_SERVICES).services }
runCatching { receivers = pm.getPackageInfo(packageName, GET_RECEIVERS).receivers } runCatching { receivers = pm.getPackageInfo(packageName, GET_RECEIVERS).receivers }
runCatching { providers = pm.getPackageInfo(packageName, GET_PROVIDERS).providers } runCatching { providers = pm.getPackageInfo(packageName, GET_PROVIDERS).providers }
} }
} }
fun Array<out ComponentInfo>.processNames() = map { it.processName ?: appProcessName }
return with(packageInfo) {
activities?.processNames().orEmpty() +
services?.processNames().orEmpty() +
receivers?.processNames().orEmpty() +
providers?.processNames().orEmpty()
}
} }
fun Context.rawResource(id: Int) = resources.openRawResource(id) fun Context.rawResource(id: Int) = resources.openRawResource(id)
......
...@@ -3,6 +3,7 @@ package com.topjohnwu.magisk.ui.hide ...@@ -3,6 +3,7 @@ package com.topjohnwu.magisk.ui.hide
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.pm.ApplicationInfo import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Process
import androidx.databinding.Bindable import androidx.databinding.Bindable
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.BR
...@@ -12,7 +13,6 @@ import com.topjohnwu.magisk.arch.filterableListOf ...@@ -12,7 +13,6 @@ import com.topjohnwu.magisk.arch.filterableListOf
import com.topjohnwu.magisk.arch.itemBindingOf import com.topjohnwu.magisk.arch.itemBindingOf
import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.ktx.get import com.topjohnwu.magisk.ktx.get
import com.topjohnwu.magisk.ktx.packageInfo
import com.topjohnwu.magisk.ktx.packageName import com.topjohnwu.magisk.ktx.packageName
import com.topjohnwu.magisk.ktx.processes import com.topjohnwu.magisk.ktx.processes
import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.magisk.utils.Utils
...@@ -67,8 +67,7 @@ class HideViewModel : BaseViewModel(), Queryable { ...@@ -67,8 +67,7 @@ class HideViewModel : BaseViewModel(), Queryable {
.asSequence() .asSequence()
.filter { it.enabled && !blacklist.contains(it.packageName) } .filter { it.enabled && !blacklist.contains(it.packageName) }
.map { HideAppInfo(it, pm) } .map { HideAppInfo(it, pm) }
.map { runCatching { createTarget(it, hides) }.getOrNull() } .map { createTarget(it, hides) }
.filterNotNull()
.filter { it.processes.isNotEmpty() } .filter { it.processes.isNotEmpty() }
.map { HideItem(it) } .map { HideItem(it) }
.toList() .toList()
...@@ -84,7 +83,7 @@ class HideViewModel : BaseViewModel(), Queryable { ...@@ -84,7 +83,7 @@ class HideViewModel : BaseViewModel(), Queryable {
private fun createTarget(info: HideAppInfo, hideList: List<HideTarget>): HideAppTarget { private fun createTarget(info: HideAppInfo, hideList: List<HideTarget>): HideAppTarget {
val pkg = info.packageName val pkg = info.packageName
val hidden = hideList.filter { it.packageName == pkg } val hidden = hideList.filter { it.packageName == pkg }
val processNames = info.packageInfo.processes.distinct() val processNames = info.processes.distinct()
val processes = processNames.map { name -> val processes = processNames.map { name ->
HideProcessInfo(name, pkg, hidden.any { name == it.process }) HideProcessInfo(name, pkg, hidden.any { name == it.process })
} }
...@@ -99,7 +98,12 @@ class HideViewModel : BaseViewModel(), Queryable { ...@@ -99,7 +98,12 @@ class HideViewModel : BaseViewModel(), Queryable {
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 isApp(uid: Int) = run {
val appId: Int = uid % 100000
appId >= Process.FIRST_APPLICATION_UID && appId <= Process.LAST_APPLICATION_UID
}
fun filterOS() = (isShowSystem && isShowOS) || isApp(it.info.uid)
fun filterQuery(): Boolean { fun filterQuery(): Boolean {
fun inName() = it.info.label.contains(query, true) fun inName() = it.info.label.contains(query, true)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment