Skip to content

Commit

Permalink
#1280 work profile apps fix for android 12
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanth committed Jun 18, 2022
1 parent 537e907 commit f5b8f93
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion app/src/main/java/dev/ukanth/ufirewall/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ public final class Api {
private static final String[] natChains = {"", "-tor-check", "-tor-filter"};
private static final String[] staticChains = {"", "-input", "-3g", "-wifi", "-reject", "-vpn", "-3g-tether", "-3g-home", "-3g-roam", "-wifi-tether", "-wifi-wan", "-wifi-lan", "-tor", "-tor-reject", "-tether"};
private static boolean globalStatus = false;


private static final Pattern dual_pattern = Pattern.compile("package:(.*) uid:(.*)", Pattern.MULTILINE);

/**
* @brief Special user/group IDs that aren't associated with
* any particular app.
Expand Down Expand Up @@ -1730,7 +1734,8 @@ private static void checkPartOfMultiUser(ApplicationInfo apinfo, String name, Li
for (Integer integer : uid1) {
int appUid = Integer.parseInt(integer + "" + apinfo.uid + "");
try{
String[] pkgs = pkgmanager.getPackagesForUid(appUid);
List<String> pkgs = getPackagesForUser(integer);
//String[] pkgs = pkgmanager.getPackagesForUid(appUid);
if (pkgs != null) {
PackageInfoData app = new PackageInfoData();
app.uid = appUid;
Expand All @@ -1757,6 +1762,21 @@ private static void checkPartOfMultiUser(ApplicationInfo apinfo, String name, Li
}
}

private static List<String> getPackagesForUser(Integer integer) {
List<String> listApps = new ArrayList<>();
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);
listApps.add(packageName);
}
}
return listApps.size() > 0 ? listApps : null;
}

private static boolean isRecentlyInstalled(String packageName) {
boolean isRecent = false;
if (recentlyInstalled != null && recentlyInstalled.contains(packageName)) {
Expand Down

0 comments on commit f5b8f93

Please sign in to comment.