fix: Fix apps reassess on root

This commit is contained in:
Alberto Ponces 2022-09-18 01:54:25 +01:00
parent 257fd46e27
commit ae801a2918
2 changed files with 25 additions and 30 deletions

View File

@ -182,11 +182,14 @@ class ManagerAPI {
List<PatchedApplication> patchedApps, List<PatchedApplication> patchedApps,
) async { ) async {
List<PatchedApplication> unsavedApps = []; List<PatchedApplication> unsavedApps = [];
bool hasRootPermissions = await _rootAPI.hasRootPermissions();
if (hasRootPermissions) {
List<String> installedApps = await _rootAPI.getInstalledApps(); List<String> installedApps = await _rootAPI.getInstalledApps();
for (String packageName in installedApps) { for (String packageName in installedApps) {
if (!patchedApps.any((app) => app.packageName == packageName)) { if (!patchedApps.any((app) => app.packageName == packageName)) {
ApplicationWithIcon? application = ApplicationWithIcon? application =
await DeviceApps.getApp(packageName, true) as ApplicationWithIcon?; await DeviceApps.getApp(packageName, true)
as ApplicationWithIcon?;
if (application != null) { if (application != null) {
unsavedApps.add( unsavedApps.add(
PatchedApplication( PatchedApplication(
@ -202,6 +205,7 @@ class ManagerAPI {
} }
} }
} }
}
List<Application> userApps = await DeviceApps.getInstalledApplications( List<Application> userApps = await DeviceApps.getInstalledApplications(
includeSystemApps: false, includeSystemApps: false,
includeAppIcons: false, includeAppIcons: false,
@ -227,7 +231,6 @@ class ManagerAPI {
} }
} }
} }
return unsavedApps; return unsavedApps;
} }
@ -260,14 +263,15 @@ class ManagerAPI {
Future<bool> isAppUninstalled(PatchedApplication app) async { Future<bool> isAppUninstalled(PatchedApplication app) async {
bool existsRoot = false; bool existsRoot = false;
bool existsNonRoot = await DeviceApps.isAppInstalled(app.packageName);
if (app.isRooted) { if (app.isRooted) {
bool hasRootPermissions = await _rootAPI.hasRootPermissions(); bool hasRootPermissions = await _rootAPI.hasRootPermissions();
if (hasRootPermissions) { if (hasRootPermissions) {
existsRoot = await _rootAPI.isAppInstalled(app.packageName); existsRoot = await _rootAPI.isAppInstalled(app.packageName);
} }
return !existsRoot || !existsNonRoot;
} }
bool existsNonRoot = await DeviceApps.isAppInstalled(app.packageName); return !existsNonRoot;
return !existsRoot && !existsNonRoot;
} }
Future<bool> hasAppUpdates(String packageName, DateTime patchDate) async { Future<bool> hasAppUpdates(String packageName, DateTime patchDate) async {

View File

@ -58,16 +58,7 @@ class RootAPI {
cmd: 'ls "$_managerDirPath"', cmd: 'ls "$_managerDirPath"',
); );
if (res != null) { if (res != null) {
List<String> apps = res.split('\n'); return res.split('\n').map((pack) => pack.trim()).toList();
List<String> toRemove = [];
for (String packageName in apps) {
bool isInstalled = await isAppInstalled(packageName);
if (!isInstalled) {
toRemove.add(packageName);
}
}
apps.removeWhere((a) => toRemove.contains(a));
return apps;
} }
} on Exception { } on Exception {
return List.empty(); return List.empty();