BlacklistViewModel: Move label check to extension

Let other classes take benefit of this check as well

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-10-22 17:10:45 +05:30
parent b6c18bb1c2
commit 1626e13fdd
3 changed files with 7 additions and 7 deletions

View File

@@ -1,11 +1,15 @@
package com.aurora.extensions
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Process
fun PackageInfo.isValidApp(): Boolean {
fun PackageInfo.isValidApp(packageManager: PackageManager): Boolean {
if (this.applicationInfo == null || this.packageName.isEmpty()) return false
// Most core AOSP system apps use their package name as label
if (this.applicationInfo!!.loadLabel(packageManager).startsWith(this.packageName)) return false
return when {
isQAndAbove() -> {
Process.isApplicationUid(this.applicationInfo!!.uid) &&

View File

@@ -236,7 +236,7 @@ object PackageUtil {
Preferences.PREFERENCE_UPDATES_EXTENDED
)
packageInfoList = packageInfoList.filter { it.isValidApp() }
packageInfoList = packageInfoList.filter { it.isValidApp(packageManager) }
/*Filter google apps*/
if (isGoogleFilterEnabled) {

View File

@@ -58,11 +58,7 @@ class BlacklistViewModel @Inject constructor(
supervisorScope {
try {
_packages.value = context.packageManager.getInstalledPackages(0)
.filter { it.isValidApp() }
.filter {
// Most core AOSP system apps use their package name as label
it.applicationInfo!!.loadLabel(context.packageManager) != it.packageName
}
.filter { it.isValidApp(context.packageManager) }
.sortedBy {
it.applicationInfo!!.loadLabel(context.packageManager).toString()
.lowercase(Locale.getDefault())