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:
@@ -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) &&
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user