Skip to content

Commit

Permalink
Merge pull request #2360 from marunjar/fix_initial_tags
Browse files Browse the repository at this point in the history
fix initial tags
  • Loading branch information
marunjar authored Jan 1, 2025
2 parents 100a7b3 + 832b77f commit d6e856f
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions app/src/main/java/fr/neamar/kiss/TagsHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Build;
import android.os.UserManager;
import android.provider.AlarmClock;
import android.util.Log;

import androidx.annotation.NonNull;

Expand All @@ -20,6 +22,7 @@
import java.util.Set;

import fr.neamar.kiss.db.DBHelper;
import fr.neamar.kiss.utils.UserHandle;

public class TagsHandler {
private final Context context;
Expand Down Expand Up @@ -136,9 +139,28 @@ private List<String> getAppsByCategory(PackageManager pm, String category) {
private List<String> getApps(PackageManager pm, Intent lookingFor) {
List<ResolveInfo> list = pm.queryIntentActivities(lookingFor, 0);
List<String> apps = new ArrayList<>(list.size());
for (ResolveInfo resolveInfo : list) {
String app = "app://" + resolveInfo.activityInfo.applicationInfo.packageName + "/" + resolveInfo.activityInfo.name;
apps.add(app);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Set<String> packageNames = new HashSet<>();
for (ResolveInfo resolveInfo : list) {
packageNames.add(resolveInfo.activityInfo.packageName);
}

UserManager manager = (UserManager) context.getSystemService(Context.USER_SERVICE);
LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
for (android.os.UserHandle profile : manager.getUserProfiles()) {
UserHandle userHandle = new UserHandle(manager.getSerialNumberForUser(profile), profile);
for (String packageName : packageNames) {
for (LauncherActivityInfo activityInfo : launcherApps.getActivityList(packageName, profile)) {
String app = userHandle.addUserSuffixToString("app://" + activityInfo.getComponentName().getPackageName() + "/" + activityInfo.getComponentName().getClassName(), '/');
apps.add(app);
}
}
}
} else {
for (ResolveInfo resolveInfo : list) {
String app = "app://" + resolveInfo.activityInfo.packageName + "/" + resolveInfo.activityInfo.name;
apps.add(app);
}
}
return apps;
}
Expand Down

0 comments on commit d6e856f

Please sign in to comment.