Delete outdated policies

This commit is contained in:
vvb2060 2022-05-07 17:52:30 +08:00 committed by John Wu
parent 358538717c
commit 68db366696

View File

@ -55,11 +55,16 @@ class SuperuserViewModel(
state = State.LOADING state = State.LOADING
val (policies, diff) = withContext(Dispatchers.IO) { val (policies, diff) = withContext(Dispatchers.IO) {
db.deleteOutdated() db.deleteOutdated()
db.delete(AppContext.applicationInfo.uid)
val policies = ArrayList<PolicyRvItem>() val policies = ArrayList<PolicyRvItem>()
val pm = AppContext.packageManager val pm = AppContext.packageManager
for (policy in db.fetchAll()) { for (policy in db.fetchAll()) {
val pkgs = pm.getPackagesForUid(policy.uid) ?: continue val pkgs = pm.getPackagesForUid(policy.uid)
policies.addAll(pkgs.mapNotNull { pkg -> if (pkgs == null) {
db.delete(policy.uid)
continue
}
val map = pkgs.mapNotNull { pkg ->
try { try {
val info = pm.getPackageInfo(pkg, MATCH_UNINSTALLED_PACKAGES) val info = pm.getPackageInfo(pkg, MATCH_UNINSTALLED_PACKAGES)
PolicyRvItem( PolicyRvItem(
@ -72,7 +77,12 @@ class SuperuserViewModel(
} catch (e: PackageManager.NameNotFoundException) { } catch (e: PackageManager.NameNotFoundException) {
null null
} }
}) }
if (map.isEmpty()) {
db.delete(policy.uid)
continue
}
policies.addAll(map)
} }
policies.sortWith(compareBy( policies.sortWith(compareBy(
{ it.appName.lowercase(currentLocale) }, { it.appName.lowercase(currentLocale) },