From 68db3666967a10e085fc8702ae72beacf6b999fa Mon Sep 17 00:00:00 2001 From: vvb2060 Date: Sat, 7 May 2022 17:52:30 +0800 Subject: [PATCH] Delete outdated policies --- .../magisk/ui/superuser/SuperuserViewModel.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt index ceca11bf4..030580462 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt @@ -55,11 +55,16 @@ class SuperuserViewModel( state = State.LOADING val (policies, diff) = withContext(Dispatchers.IO) { db.deleteOutdated() + db.delete(AppContext.applicationInfo.uid) val policies = ArrayList() val pm = AppContext.packageManager for (policy in db.fetchAll()) { - val pkgs = pm.getPackagesForUid(policy.uid) ?: continue - policies.addAll(pkgs.mapNotNull { pkg -> + val pkgs = pm.getPackagesForUid(policy.uid) + if (pkgs == null) { + db.delete(policy.uid) + continue + } + val map = pkgs.mapNotNull { pkg -> try { val info = pm.getPackageInfo(pkg, MATCH_UNINSTALLED_PACKAGES) PolicyRvItem( @@ -72,7 +77,12 @@ class SuperuserViewModel( } catch (e: PackageManager.NameNotFoundException) { null } - }) + } + if (map.isEmpty()) { + db.delete(policy.uid) + continue + } + policies.addAll(map) } policies.sortWith(compareBy( { it.appName.lowercase(currentLocale) },