Search in sources :

Example 61 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project lnch by italankin.

the class LauncherActivityInfoUtils method groupByPackage.

static Map<String, List<LauncherActivityInfo>> groupByPackage(List<LauncherActivityInfo> infoList) {
    Map<String, List<LauncherActivityInfo>> infosByPackageName = new LinkedHashMap<>(infoList.size());
    for (LauncherActivityInfo info : infoList) {
        String packageName = info.getApplicationInfo().packageName;
        List<LauncherActivityInfo> list = infosByPackageName.get(packageName);
        if (list == null) {
            list = new ArrayList<>(1);
            infosByPackageName.put(packageName, list);
        }
        list.add(info);
    }
    return infosByPackageName;
}
Also used : LauncherActivityInfo(android.content.pm.LauncherActivityInfo) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap)

Example 62 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project lnch by italankin.

the class PackagesMap method poll.

/**
 * Get matching {@link LauncherActivityInfo} for a given {@link AppDescriptor}.
 * If {@code null} is returned, the app probably got deleted.
 */
LauncherActivityInfo poll(AppDescriptor item) {
    List<LauncherActivityInfo> infos = packages.get(item.packageName);
    if (infos == null || infos.isEmpty()) {
        return null;
    }
    if (infos.size() == 1) {
        LauncherActivityInfo result = infos.remove(0);
        packages.remove(item.packageName);
        return result;
    } else if (item.componentName != null) {
        Iterator<LauncherActivityInfo> iter = infos.iterator();
        while (iter.hasNext()) {
            LauncherActivityInfo info = iter.next();
            String componentName = getComponentName(info);
            if (componentName.equals(item.componentName)) {
                iter.remove();
                return info;
            }
        }
    }
    return null;
}
Also used : LauncherActivityInfo(android.content.pm.LauncherActivityInfo) Iterator(java.util.Iterator)

Example 63 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project android_packages_apps_Launcher3 by ProtonAOSP.

the class ShortcutConfigActivityInfo method queryList.

public static List<ShortcutConfigActivityInfo> queryList(Context context, @Nullable PackageUserKey packageUser) {
    List<ShortcutConfigActivityInfo> result = new ArrayList<>();
    UserHandle myUser = Process.myUserHandle();
    final List<UserHandle> users;
    final String packageName;
    if (packageUser == null) {
        users = UserCache.INSTANCE.get(context).getUserProfiles();
        packageName = null;
    } else {
        users = Collections.singletonList(packageUser.mUser);
        packageName = packageUser.mPackageName;
    }
    LauncherApps launcherApps = context.getSystemService(LauncherApps.class);
    for (UserHandle user : users) {
        boolean ignoreTargetSdk = myUser.equals(user);
        for (LauncherActivityInfo activityInfo : launcherApps.getShortcutConfigActivityList(packageName, user)) {
            if (ignoreTargetSdk || activityInfo.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
                result.add(new ShortcutConfigActivityInfoVO(activityInfo));
            }
        }
    }
    return result;
}
Also used : UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) LauncherApps(android.content.pm.LauncherApps)

Example 64 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project android_packages_apps_Launcher3 by ProtonAOSP.

the class SecondaryDropTarget method getUninstallTarget.

/**
 * @return the component name that should be uninstalled or null.
 */
private ComponentName getUninstallTarget(ItemInfo item) {
    Intent intent = null;
    UserHandle user = null;
    if (item != null && item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
        intent = item.getIntent();
        user = item.user;
    }
    if (intent != null) {
        LauncherActivityInfo info = mLauncher.getSystemService(LauncherApps.class).resolveActivity(intent, user);
        if (info != null && (info.getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
            return info.getComponentName();
        }
    }
    return null;
}
Also used : UserHandle(android.os.UserHandle) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) Intent(android.content.Intent) LauncherApps(android.content.pm.LauncherApps)

Example 65 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project android_packages_apps_Launcher3 by ProtonAOSP.

the class LoaderTask method loadAllApps.

private List<LauncherActivityInfo> loadAllApps() {
    final List<UserHandle> profiles = mUserCache.getUserProfiles();
    List<LauncherActivityInfo> allActivityList = new ArrayList<>();
    // Clear the list of apps
    mBgAllAppsList.clear();
    List<IconRequestInfo<AppInfo>> iconRequestInfos = new ArrayList<>();
    for (UserHandle user : profiles) {
        // Query for the set of apps
        final List<LauncherActivityInfo> apps = mLauncherApps.getActivityList(null, user);
        // TODO: Fix this. Only fail for the current user.
        if (apps == null || apps.isEmpty()) {
            return allActivityList;
        }
        boolean quietMode = mUserManagerState.isUserQuiet(user);
        // Create the ApplicationInfos
        for (int i = 0; i < apps.size(); i++) {
            LauncherActivityInfo app = apps.get(i);
            AppInfo appInfo = new AppInfo(app, user, quietMode);
            iconRequestInfos.add(new IconRequestInfo<>(appInfo, app, /* useLowResIcon= */
            false));
            mBgAllAppsList.add(appInfo, app, !FeatureFlags.ENABLE_BULK_ALL_APPS_ICON_LOADING.get());
        }
        allActivityList.addAll(apps);
    }
    if (FeatureFlags.PROMISE_APPS_IN_ALL_APPS.get()) {
        // get all active sessions and add them to the all apps list
        for (PackageInstaller.SessionInfo info : mSessionHelper.getAllVerifiedSessions()) {
            AppInfo promiseAppInfo = mBgAllAppsList.addPromiseApp(mApp.getContext(), PackageInstallInfo.fromInstallingState(info), !FeatureFlags.ENABLE_BULK_ALL_APPS_ICON_LOADING.get());
            if (promiseAppInfo != null) {
                iconRequestInfos.add(new IconRequestInfo<>(promiseAppInfo, /* launcherActivityInfo= */
                null, promiseAppInfo.usingLowResIcon()));
            }
        }
    }
    if (FeatureFlags.ENABLE_BULK_ALL_APPS_ICON_LOADING.get()) {
        Trace.beginSection("LoadAllAppsIconsInBulk");
        try {
            mIconCache.getTitlesAndIconsInBulk(iconRequestInfos);
            iconRequestInfos.forEach(iconRequestInfo -> mBgAllAppsList.updateSectionName(iconRequestInfo.itemInfo));
        } finally {
            Trace.endSection();
        }
    }
    mBgAllAppsList.setFlags(FLAG_QUIET_MODE_ENABLED, mUserManagerState.isAnyProfileQuietModeEnabled());
    mBgAllAppsList.setFlags(FLAG_HAS_SHORTCUT_PERMISSION, hasShortcutsPermission(mApp.getContext()));
    mBgAllAppsList.setFlags(FLAG_QUIET_MODE_CHANGE_PERMISSION, mApp.getContext().checkSelfPermission("android.permission.MODIFY_QUIET_MODE") == PackageManager.PERMISSION_GRANTED);
    mBgAllAppsList.getAndResetChangeFlag();
    return allActivityList;
}
Also used : ArrayList(java.util.ArrayList) IconRequestInfo(com.android.launcher3.model.data.IconRequestInfo) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) AppInfo(com.android.launcher3.model.data.AppInfo) SessionInfo(android.content.pm.PackageInstaller.SessionInfo) UserHandle(android.os.UserHandle) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) PackageInstaller(android.content.pm.PackageInstaller)

Aggregations

LauncherActivityInfo (android.content.pm.LauncherActivityInfo)122 LauncherApps (android.content.pm.LauncherApps)62 ArrayList (java.util.ArrayList)51 UserHandle (android.os.UserHandle)44 Intent (android.content.Intent)32 ComponentName (android.content.ComponentName)27 List (java.util.List)26 AppInfo (com.android.launcher3.model.data.AppInfo)23 ShortcutInfo (android.content.pm.ShortcutInfo)22 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)21 Context (android.content.Context)19 Point (android.graphics.Point)19 SessionInfo (android.content.pm.PackageInstaller.SessionInfo)16 SuppressLint (android.annotation.SuppressLint)14 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)13 PackageManager (android.content.pm.PackageManager)12 PackageUserKey (com.android.launcher3.util.PackageUserKey)11 UserManager (android.os.UserManager)10 CancellationException (java.util.concurrent.CancellationException)10 PackageInstaller (android.content.pm.PackageInstaller)9