diff --git a/app/src/main/kotlin/dev/sanmer/pi/compat/PackageInfoCompat.kt b/app/src/main/kotlin/dev/sanmer/pi/compat/PackageInfoCompat.kt index fcd31fc7..b95988eb 100644 --- a/app/src/main/kotlin/dev/sanmer/pi/compat/PackageInfoCompat.kt +++ b/app/src/main/kotlin/dev/sanmer/pi/compat/PackageInfoCompat.kt @@ -1,5 +1,6 @@ package dev.sanmer.pi.compat +import android.content.pm.ApplicationInfo import android.content.pm.PackageInfo import android.content.pm.PackageInfoHidden import dev.rikka.tools.refine.Refine @@ -11,4 +12,8 @@ object PackageInfoCompat { val PackageInfo.isPreinstalled get() = lastUpdateTime <= 1230768000000 // 2009-01-01 08:00:00 GMT+8 + + val PackageInfo.isSystemApp get() = + applicationInfo.flags and (ApplicationInfo.FLAG_SYSTEM or + ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0 } \ No newline at end of file diff --git a/app/src/main/kotlin/dev/sanmer/pi/ui/activity/InstallActivity.kt b/app/src/main/kotlin/dev/sanmer/pi/ui/activity/InstallActivity.kt index a1754b9c..2dc1fbd7 100644 --- a/app/src/main/kotlin/dev/sanmer/pi/ui/activity/InstallActivity.kt +++ b/app/src/main/kotlin/dev/sanmer/pi/ui/activity/InstallActivity.kt @@ -13,9 +13,10 @@ import androidx.compose.runtime.setValue import androidx.lifecycle.lifecycleScope import dagger.hilt.android.AndroidEntryPoint import dev.sanmer.pi.app.Const -import dev.sanmer.pi.compat.ShizukuCompat import dev.sanmer.pi.compat.ActivityCompat +import dev.sanmer.pi.compat.PackageInfoCompat.isSystemApp import dev.sanmer.pi.compat.PackageManagerCompat +import dev.sanmer.pi.compat.ShizukuCompat import dev.sanmer.pi.model.IPackageInfo import dev.sanmer.pi.repository.LocalRepository import dev.sanmer.pi.service.InstallService.Companion.startInstallService @@ -142,7 +143,9 @@ class InstallActivity : ComponentActivity() { return runCatching { PackageManagerCompat.getPackageInfo( callingPackage, 0, 0 - ) + ).let { + if (it.isSystemApp) null else it + } }.getOrNull() } diff --git a/app/src/main/kotlin/dev/sanmer/pi/viewmodel/AppsViewModel.kt b/app/src/main/kotlin/dev/sanmer/pi/viewmodel/AppsViewModel.kt index dde52cc1..d97d467f 100644 --- a/app/src/main/kotlin/dev/sanmer/pi/viewmodel/AppsViewModel.kt +++ b/app/src/main/kotlin/dev/sanmer/pi/viewmodel/AppsViewModel.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.toMutableStateList import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel +import dev.sanmer.pi.compat.PackageInfoCompat.isSystemApp import dev.sanmer.pi.compat.PackageManagerCompat import dev.sanmer.pi.model.IPackageInfo import dev.sanmer.pi.repository.LocalRepository @@ -80,14 +81,8 @@ class AppsViewModel @Inject constructor( ) == true } - val isNotSystemApp: (PackageInfo) -> Boolean = { - it.applicationInfo.flags and (ApplicationInfo.FLAG_SYSTEM or - ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0 - } - allPackages.filter { - isRequestedInstall(it) && isNotSystemApp(it) && - it.applicationInfo.enabled + isRequestedInstall(it) && !it.isSystemApp && it.applicationInfo.enabled } }