use of android.content.pm.LauncherActivityInfo in project island by oasisfeng.
the class Users method refreshUsers.
/**
* This method should not be called under normal circumstance.
*/
public static void refreshUsers(final Context context) {
final List<UserHandle> owner_and_profiles = requireNonNull((UserManager) context.getSystemService(USER_SERVICE)).getUserProfiles();
final List<UserHandle> profiles_managed_by_island = new ArrayList<>(owner_and_profiles.size() - 1);
if (isOwner()) {
final String ui_module = Modules.getMainLaunchActivity(context).getPackageName();
final LauncherApps la = context.getSystemService(LauncherApps.class);
final String activity_in_owner = la.getActivityList(ui_module, CURRENT).get(0).getName();
for (final UserHandle user : owner_and_profiles) {
if (isOwner(user))
owner = user;
else
for (final LauncherActivityInfo activity : la.getActivityList(ui_module, user)) if (!activity.getName().equals(activity_in_owner)) {
profiles_managed_by_island.add(user);
Log.i(TAG, "Profile managed by Island: " + toId(user));
} else
Log.i(TAG, "Profile not managed by Island: " + toId(user));
}
} else
for (final UserHandle user : owner_and_profiles) {
if (isOwner(user))
owner = user;
else if (user.equals(CURRENT)) {
profiles_managed_by_island.add(user);
Log.i(TAG, "Profile managed by Island: " + toId(user));
} else
Log.w(TAG, "Skip sibling profile (may not managed by Island): " + toId(user));
}
profile = profiles_managed_by_island.isEmpty() ? null : profiles_managed_by_island.get(0);
sProfilesManagedByIsland = Collections.unmodifiableList(profiles_managed_by_island);
try {
sCurrentProfileManagedByIsland = new DevicePolicies(context).isProfileOwner();
} catch (final RuntimeException e) {
Log.e(TAG, "Error checking current profile", e);
}
}
use of android.content.pm.LauncherActivityInfo in project KISS by Neamar.
the class IconsHandler method getDefaultAppDrawable.
public Drawable getDefaultAppDrawable(ComponentName componentName, UserHandle userHandle) {
try {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
LauncherApps launcher = (LauncherApps) ctx.getSystemService(Context.LAUNCHER_APPS_SERVICE);
LauncherActivityInfo info = launcher.getActivityList(componentName.getPackageName(), userHandle.getRealHandle()).get(0);
return info.getBadgedIcon(0);
} else {
return pm.getActivityIcon(componentName);
}
} catch (NameNotFoundException | IndexOutOfBoundsException e) {
Log.e(TAG, "Unable to found component " + componentName.toString() + e);
return null;
}
}
use of android.content.pm.LauncherActivityInfo in project KISS by Neamar.
the class LoadAppPojos method doInBackground.
@Override
protected ArrayList<AppPojo> doInBackground(Void... params) {
long start = System.nanoTime();
ArrayList<AppPojo> apps = new ArrayList<>();
String excludedAppList = PreferenceManager.getDefaultSharedPreferences(context).getString("excluded-apps-list", context.getPackageName() + ";");
List excludedApps = Arrays.asList(excludedAppList.split(";"));
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
UserManager manager = (UserManager) context.getSystemService(Context.USER_SERVICE);
LauncherApps launcher = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
// Handle multi-profile support introduced in Android 5 (#542)
for (android.os.UserHandle profile : manager.getUserProfiles()) {
UserHandle user = new UserHandle(manager.getSerialNumberForUser(profile), profile);
for (LauncherActivityInfo activityInfo : launcher.getActivityList(null, profile)) {
ApplicationInfo appInfo = activityInfo.getApplicationInfo();
String fullPackageName = user.addUserSuffixToString(appInfo.packageName, '#');
if (!excludedApps.contains(fullPackageName)) {
AppPojo app = new AppPojo();
app.id = user.addUserSuffixToString(pojoScheme + appInfo.packageName + "/" + activityInfo.getName(), '/');
app.setName(activityInfo.getLabel().toString());
app.packageName = appInfo.packageName;
app.activityName = activityInfo.getName();
// Wrap Android user handle in opaque container that will work across
// all Android versions
app.userHandle = user;
app.setTags(tagsHandler.getTags(app.id));
apps.add(app);
}
}
}
} else {
PackageManager manager = context.getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
for (ResolveInfo info : manager.queryIntentActivities(mainIntent, 0)) {
ApplicationInfo appInfo = info.activityInfo.applicationInfo;
if (!excludedApps.contains(appInfo.packageName)) {
AppPojo app = new AppPojo();
app.id = pojoScheme + appInfo.packageName + "/" + info.activityInfo.name;
app.setName(info.loadLabel(manager).toString());
app.packageName = appInfo.packageName;
app.activityName = info.activityInfo.name;
app.userHandle = new UserHandle();
app.setTags(tagsHandler.getTags(app.id));
apps.add(app);
}
}
}
// Apply app sorting preference
if (prefs.getString("sort-apps", "alphabetical").equals("invertedAlphabetical")) {
Collections.sort(apps, Collections.reverseOrder(new AppPojo.NameComparator()));
} else {
Collections.sort(apps, new AppPojo.NameComparator());
}
long end = System.nanoTime();
Log.i("time", Long.toString((end - start) / 1000000) + " milliseconds to list apps");
return apps;
}
use of android.content.pm.LauncherActivityInfo in project Taskbar by farmerbb.
the class StartMenuController method generateAppEntries.
@VisibleForTesting
List<AppEntry> generateAppEntries(Context context, UserManager userManager, PackageManager pm, List<LauncherActivityInfo> queryList) {
final List<AppEntry> entries = new ArrayList<>();
Drawable defaultIcon = pm.getDefaultActivityIcon();
for (LauncherActivityInfo appInfo : queryList) {
// Attempt to work around frequently reported OutOfMemoryErrors
String label;
Drawable icon;
try {
label = appInfo.getLabel().toString();
icon = IconCache.getInstance(context).getIcon(context, pm, appInfo);
} catch (OutOfMemoryError e) {
System.gc();
label = appInfo.getApplicationInfo().packageName;
icon = defaultIcon;
}
String packageName = appInfo.getApplicationInfo().packageName;
ComponentName componentName = new ComponentName(packageName, appInfo.getName());
AppEntry newEntry = new AppEntry(packageName, componentName.flattenToString(), label, icon, false);
newEntry.setUserId(userManager.getSerialNumberForUser(appInfo.getUser()));
entries.add(newEntry);
}
return entries;
}
use of android.content.pm.LauncherActivityInfo in project Taskbar by farmerbb.
the class StartMenuController method refreshApps.
private void refreshApps(final String query, final boolean firstDraw) {
if (thread != null)
thread.interrupt();
handler = U.newHandler();
thread = new Thread(() -> {
if (pm == null)
pm = context.getPackageManager();
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
final List<UserHandle> userHandles = userManager.getUserProfiles();
final List<LauncherActivityInfo> unfilteredList = new ArrayList<>();
for (UserHandle handle : userHandles) {
unfilteredList.addAll(launcherApps.getActivityList(null, handle));
}
final List<LauncherActivityInfo> topAppsList = new ArrayList<>();
final List<LauncherActivityInfo> allAppsList = new ArrayList<>();
final List<LauncherActivityInfo> list = new ArrayList<>();
TopApps topApps = TopApps.getInstance(context);
for (LauncherActivityInfo appInfo : unfilteredList) {
String userSuffix = ":" + userManager.getSerialNumberForUser(appInfo.getUser());
if (topApps.isTopApp(appInfo.getComponentName().flattenToString() + userSuffix) || topApps.isTopApp(appInfo.getComponentName().flattenToString()) || topApps.isTopApp(appInfo.getName()))
topAppsList.add(appInfo);
}
Blacklist blacklist = Blacklist.getInstance(context);
for (LauncherActivityInfo appInfo : unfilteredList) {
String userSuffix = ":" + userManager.getSerialNumberForUser(appInfo.getUser());
if (!(blacklist.isBlocked(appInfo.getComponentName().flattenToString() + userSuffix) || blacklist.isBlocked(appInfo.getComponentName().flattenToString()) || blacklist.isBlocked(appInfo.getName())) && !(topApps.isTopApp(appInfo.getComponentName().flattenToString() + userSuffix) || topApps.isTopApp(appInfo.getComponentName().flattenToString()) || topApps.isTopApp(appInfo.getName())))
allAppsList.add(appInfo);
}
Collections.sort(topAppsList, comparator);
Collections.sort(allAppsList, comparator);
list.addAll(topAppsList);
list.addAll(allAppsList);
topAppsList.clear();
allAppsList.clear();
List<LauncherActivityInfo> queryList;
if (query == null)
queryList = list;
else {
queryList = new ArrayList<>();
for (LauncherActivityInfo appInfo : list) {
if (appInfo.getLabel().toString().toLowerCase().contains(query.toLowerCase()))
queryList.add(appInfo);
}
}
// Now that we've generated the list of apps,
// we need to determine if we need to redraw the start menu or not
boolean shouldRedrawStartMenu = false;
List<String> finalApplicationIds = new ArrayList<>();
if (query == null && !firstDraw) {
for (LauncherActivityInfo appInfo : queryList) {
finalApplicationIds.add(appInfo.getApplicationInfo().packageName);
}
if (finalApplicationIds.size() != currentStartMenuIds.size())
shouldRedrawStartMenu = true;
else {
for (int i = 0; i < finalApplicationIds.size(); i++) {
if (!finalApplicationIds.get(i).equals(currentStartMenuIds.get(i))) {
shouldRedrawStartMenu = true;
break;
}
}
}
} else
shouldRedrawStartMenu = true;
if (shouldRedrawStartMenu) {
if (query == null)
currentStartMenuIds = finalApplicationIds;
final List<AppEntry> entries = generateAppEntries(context, userManager, pm, queryList);
handler.post(() -> {
String queryText = searchView.getQuery().toString();
if (query == null && queryText.length() == 0 || query != null && query.equals(queryText)) {
if (firstDraw) {
SharedPreferences pref = U.getSharedPreferences(context);
if (pref.getString(PREF_START_MENU_LAYOUT, "grid").equals("grid")) {
startMenu.setNumColumns(context.getResources().getInteger(R.integer.tb_start_menu_columns));
adapter = new StartMenuAdapter(context, R.layout.tb_row_alt, entries);
} else
adapter = new StartMenuAdapter(context, R.layout.tb_row, entries);
startMenu.setAdapter(adapter);
}
int position = startMenu.getFirstVisiblePosition();
if (!firstDraw && adapter != null)
adapter.updateList(entries);
startMenu.setSelection(position);
if (adapter != null && adapter.getCount() > 0)
textView.setText(null);
else if (query != null)
textView.setText(context.getString(Patterns.WEB_URL.matcher(query).matches() ? R.string.tb_press_enter_alt : R.string.tb_press_enter));
else
textView.setText(context.getString(R.string.tb_nothing_to_see_here));
}
});
}
});
thread.start();
}
Aggregations