diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index b77a0d4595..aefba39011 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -182,23 +182,27 @@ class ManagerAPI { List patchedApps, ) async { List unsavedApps = []; - List installedApps = await _rootAPI.getInstalledApps(); - for (String packageName in installedApps) { - if (!patchedApps.any((app) => app.packageName == packageName)) { - ApplicationWithIcon? application = - await DeviceApps.getApp(packageName, true) as ApplicationWithIcon?; - if (application != null) { - unsavedApps.add( - PatchedApplication( - name: application.appName, - packageName: application.packageName, - version: application.versionName!, - apkFilePath: application.apkFilePath, - icon: application.icon, - patchDate: DateTime.now(), - isRooted: true, - ), - ); + bool hasRootPermissions = await _rootAPI.hasRootPermissions(); + if (hasRootPermissions) { + List installedApps = await _rootAPI.getInstalledApps(); + for (String packageName in installedApps) { + if (!patchedApps.any((app) => app.packageName == packageName)) { + ApplicationWithIcon? application = + await DeviceApps.getApp(packageName, true) + as ApplicationWithIcon?; + if (application != null) { + unsavedApps.add( + PatchedApplication( + name: application.appName, + packageName: application.packageName, + version: application.versionName!, + apkFilePath: application.apkFilePath, + icon: application.icon, + patchDate: DateTime.now(), + isRooted: true, + ), + ); + } } } } @@ -227,7 +231,6 @@ class ManagerAPI { } } } - return unsavedApps; } @@ -260,14 +263,15 @@ class ManagerAPI { Future isAppUninstalled(PatchedApplication app) async { bool existsRoot = false; + bool existsNonRoot = await DeviceApps.isAppInstalled(app.packageName); if (app.isRooted) { bool hasRootPermissions = await _rootAPI.hasRootPermissions(); if (hasRootPermissions) { existsRoot = await _rootAPI.isAppInstalled(app.packageName); } + return !existsRoot || !existsNonRoot; } - bool existsNonRoot = await DeviceApps.isAppInstalled(app.packageName); - return !existsRoot && !existsNonRoot; + return !existsNonRoot; } Future hasAppUpdates(String packageName, DateTime patchDate) async { diff --git a/lib/services/root_api.dart b/lib/services/root_api.dart index 57179a27ff..9f96efe0de 100644 --- a/lib/services/root_api.dart +++ b/lib/services/root_api.dart @@ -58,16 +58,7 @@ class RootAPI { cmd: 'ls "$_managerDirPath"', ); if (res != null) { - List apps = res.split('\n'); - List toRemove = []; - for (String packageName in apps) { - bool isInstalled = await isAppInstalled(packageName); - if (!isInstalled) { - toRemove.add(packageName); - } - } - apps.removeWhere((a) => toRemove.contains(a)); - return apps; + return res.split('\n').map((pack) => pack.trim()).toList(); } } on Exception { return List.empty();