Skip to content

Commit

Permalink
* [Issue #3] Bug in the implementation of Api.getPackagesForUser() le…
Browse files Browse the repository at this point in the history
…ading to empty package list.

Fixed the error in the syntax of the 'pm list packages' command executed in the Api.getPackagesForUser() leading to an execution error and consequently to an empty package list getting returned.
  • Loading branch information
amaa-99 committed Aug 9, 2023
1 parent 59d20c0 commit 89f8a83
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions app/src/main/java/dev/ukanth/ufirewall/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ public static List<PackageInfoData> getApps(Context ctx, GetAppList appList) {
}
}
}
//use pm list packages -f -U --user 10

int pkgManagerFlags = PackageManager.GET_META_DATA;
// it's useless to iterate over uninstalled packages if we don't support multi-profile apps
if (G.supportDual()) {
Expand Down Expand Up @@ -1686,19 +1686,15 @@ private static boolean packagesExistForUserUid(HashMap<Integer,String> pkgs, int
}

public static HashMap<Integer, String> getPackagesForUser(List<Integer> userProfile) {
HashMap<Integer,String> listApps = new HashMap<>();
for(Integer integer: userProfile) {
Shell.Result result = Shell.cmd("pm list packages -U --user " + integer).exec();
List<String> out = result.getOut();
Matcher matcher;
for (String item : out) {
matcher = dual_pattern.matcher(item);
if (matcher.find() && matcher.groupCount() > 0) {
String packageName = matcher.group(1);
String packageId = matcher.group(2);
Log.i(TAG, packageId + " " + packageName);
listApps.put(Integer.parseInt(packageId), packageName);
}
HashMap<Integer, String> listApps = new HashMap<>();
PackageManager pkgManager = ctx.getPackageManager();
for (Integer uid : userProfile) {
List<ApplicationInfo> installed = pkgManager.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo appInfo : installed) {
String packageName = appInfo.packageName;
int packageId = appInfo.uid;
Log.i(TAG, packageId + " " + packageName);
listApps.put(packageId, packageName);
}
}
return listApps.size() > 0 ? listApps : null;
Expand Down

0 comments on commit 89f8a83

Please sign in to comment.