Skip to content

Commit

Permalink
Filter out System App in getSourceInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
SanmerDev committed Nov 25, 2023
1 parent 0e4aaa5 commit e09d7c7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
5 changes: 5 additions & 0 deletions app/src/main/kotlin/dev/sanmer/pi/compat/PackageInfoCompat.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -142,7 +143,9 @@ class InstallActivity : ComponentActivity() {
return runCatching {
PackageManagerCompat.getPackageInfo(
callingPackage, 0, 0
)
).let {
if (it.isSystemApp) null else it
}
}.getOrNull()
}

Expand Down
9 changes: 2 additions & 7 deletions app/src/main/kotlin/dev/sanmer/pi/viewmodel/AppsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit e09d7c7

Please sign in to comment.