diff --git a/app/src/main/java/dev/ukanth/ufirewall/Api.java b/app/src/main/java/dev/ukanth/ufirewall/Api.java index 2fd581b3..de23e035 100644 --- a/app/src/main/java/dev/ukanth/ufirewall/Api.java +++ b/app/src/main/java/dev/ukanth/ufirewall/Api.java @@ -1533,6 +1533,8 @@ public static List getApps(Context ctx, GetAppList appList) { SparseArray multiUserAppsMap = new SparseArray<>(); + HashMap listMaps = getPackagesForUser(listOfUids); + for (int i = 0; i < installed.size(); i++) { //for (ApplicationInfo apinfo : installed) { count = count + 1; @@ -1603,7 +1605,7 @@ public static List getApps(Context ctx, GetAppList appList) { app.selected_tor = true; } if (G.supportDual()) { - checkPartOfMultiUser(apinfo, name, listOfUids, pkgmanager, multiUserAppsMap); + checkPartOfMultiUser(apinfo, name, listOfUids, listMaps, multiUserAppsMap); } } @@ -1729,14 +1731,13 @@ public static List getSpecialData() { return specialData; } - private static void checkPartOfMultiUser(ApplicationInfo apinfo, String name, List uid1, PackageManager pkgmanager, SparseArray syncMap) { + private static void checkPartOfMultiUser(ApplicationInfo apinfo, String name, List uid1, HashMap pkgs, SparseArray syncMap) { try { for (Integer integer : uid1) { int appUid = Integer.parseInt(integer + "" + apinfo.uid + ""); try{ - List pkgs = getPackagesForUser(integer); //String[] pkgs = pkgmanager.getPackagesForUid(appUid); - if (pkgs != null) { + if (packagesExistForUserUid(pkgs, appUid)) { PackageInfoData app = new PackageInfoData(); app.uid = appUid; app.installTime = new File(apinfo.sourceDir).lastModified(); @@ -1762,16 +1763,27 @@ private static void checkPartOfMultiUser(ApplicationInfo apinfo, String name, Li } } - private static List getPackagesForUser(Integer integer) { - List listApps = new ArrayList<>(); - Shell.Result result = Shell.cmd("pm list packages -U --user " + integer).exec(); - List 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); - listApps.add(packageName); + private static boolean packagesExistForUserUid(HashMap pkgs, int appUid) { + if(pkgs.containsKey(appUid)){ + return true; + } + return false; + } + + private static HashMap getPackagesForUser(List userProfile) { + HashMap listApps = new HashMap<>(); + for(Integer integer: userProfile) { + Shell.Result result = Shell.cmd("pm list packages -U --user " + integer).exec(); + List 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); + } } } return listApps.size() > 0 ? listApps : null;