Skip to content

Commit

Permalink
#1249 - work profile fix for android 12
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanth committed Jun 22, 2022
1 parent 5cc3362 commit e30e668
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions app/src/main/java/dev/ukanth/ufirewall/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,8 @@ public static List<PackageInfoData> getApps(Context ctx, GetAppList appList) {

SparseArray<PackageInfoData> multiUserAppsMap = new SparseArray<>();

HashMap<Integer,String> listMaps = getPackagesForUser(listOfUids);

for (int i = 0; i < installed.size(); i++) {
//for (ApplicationInfo apinfo : installed) {
count = count + 1;
Expand Down Expand Up @@ -1603,7 +1605,7 @@ public static List<PackageInfoData> getApps(Context ctx, GetAppList appList) {
app.selected_tor = true;
}
if (G.supportDual()) {
checkPartOfMultiUser(apinfo, name, listOfUids, pkgmanager, multiUserAppsMap);
checkPartOfMultiUser(apinfo, name, listOfUids, listMaps, multiUserAppsMap);
}
}

Expand Down Expand Up @@ -1729,14 +1731,13 @@ public static List<PackageInfoData> getSpecialData() {
return specialData;
}

private static void checkPartOfMultiUser(ApplicationInfo apinfo, String name, List<Integer> uid1, PackageManager pkgmanager, SparseArray<PackageInfoData> syncMap) {
private static void checkPartOfMultiUser(ApplicationInfo apinfo, String name, List<Integer> uid1, HashMap<Integer,String> pkgs, SparseArray<PackageInfoData> syncMap) {
try {
for (Integer integer : uid1) {
int appUid = Integer.parseInt(integer + "" + apinfo.uid + "");
try{
List<String> 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();
Expand All @@ -1762,16 +1763,27 @@ 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);
private static boolean packagesExistForUserUid(HashMap<Integer,String> pkgs, int appUid) {
if(pkgs.containsKey(appUid)){
return true;
}
return false;
}

private 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);
}
}
}
return listApps.size() > 0 ? listApps : null;
Expand Down

0 comments on commit e30e668

Please sign in to comment.