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
|
package com.aurora.extensions
|
||||||
|
|
||||||
import android.content.pm.PackageInfo
|
import android.content.pm.PackageInfo
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.os.Process
|
import android.os.Process
|
||||||
|
|
||||||
fun PackageInfo.isValidApp(): Boolean {
|
fun PackageInfo.isValidApp(packageManager: PackageManager): Boolean {
|
||||||
if (this.applicationInfo == null || this.packageName.isEmpty()) return false
|
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 {
|
return when {
|
||||||
isQAndAbove() -> {
|
isQAndAbove() -> {
|
||||||
Process.isApplicationUid(this.applicationInfo!!.uid) &&
|
Process.isApplicationUid(this.applicationInfo!!.uid) &&
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ object PackageUtil {
|
|||||||
Preferences.PREFERENCE_UPDATES_EXTENDED
|
Preferences.PREFERENCE_UPDATES_EXTENDED
|
||||||
)
|
)
|
||||||
|
|
||||||
packageInfoList = packageInfoList.filter { it.isValidApp() }
|
packageInfoList = packageInfoList.filter { it.isValidApp(packageManager) }
|
||||||
|
|
||||||
/*Filter google apps*/
|
/*Filter google apps*/
|
||||||
if (isGoogleFilterEnabled) {
|
if (isGoogleFilterEnabled) {
|
||||||
|
|||||||
@@ -58,11 +58,7 @@ class BlacklistViewModel @Inject constructor(
|
|||||||
supervisorScope {
|
supervisorScope {
|
||||||
try {
|
try {
|
||||||
_packages.value = context.packageManager.getInstalledPackages(0)
|
_packages.value = context.packageManager.getInstalledPackages(0)
|
||||||
.filter { it.isValidApp() }
|
.filter { it.isValidApp(context.packageManager) }
|
||||||
.filter {
|
|
||||||
// Most core AOSP system apps use their package name as label
|
|
||||||
it.applicationInfo!!.loadLabel(context.packageManager) != it.packageName
|
|
||||||
}
|
|
||||||
.sortedBy {
|
.sortedBy {
|
||||||
it.applicationInfo!!.loadLabel(context.packageManager).toString()
|
it.applicationInfo!!.loadLabel(context.packageManager).toString()
|
||||||
.lowercase(Locale.getDefault())
|
.lowercase(Locale.getDefault())
|
||||||
|
|||||||
Reference in New Issue
Block a user