Java Code Examples for android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES

The following are Jave code examples for showing how to use MATCH_UNINSTALLED_PACKAGES of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: LaunchEnr   File: GridSizeMigrationTask.java   View Source Code Vote up 6 votes
protected static HashSet<String> getValidPackages(Context context) {
    // Initialize list of valid packages. This contain all the packages which are already on
    // the device and packages which are being installed. Any item which doesn't belong to
    // this set is removed.
    // Since the loader removes such items anyway, removing these items here doesn't cause
    // any extra data loss and gives us more free space on the grid for better migration.
    HashSet validPackages = new HashSet<>();
    int uninstalled = android.os.Build.VERSION.SDK_INT >= 24 ? PackageManager.MATCH_UNINSTALLED_PACKAGES : PackageManager.GET_UNINSTALLED_PACKAGES;

    for (PackageInfo info : context.getPackageManager()
            .getInstalledPackages(uninstalled)) {
        validPackages.add(info.packageName);
    }
    validPackages.addAll(PackageInstallerCompat.getInstance(context)
            .updateAndGetActiveSessionCache().keySet());
    return validPackages;
}
 
Example 2
Project: LaunchEnr   File: UninstallDropTarget.java   View Source Code Vote up 6 votes
/**
 * Notifies the {@param callback} whether the uninstall was successful or not.
 *
 * Since there is no direct callback for an uninstall request, we check the package existence
 * when the launch resumes next time. This assumes that the uninstall activity will finish only
 * after the task is completed
 */
protected static void sendUninstallResult(
        final Launcher launcher, boolean activityStarted,
        final ComponentName cn, final UserHandle user,
        final DropTargetResultCallback callback) {
    if (activityStarted)  {
        final Runnable checkIfUninstallWasSuccess = new Runnable() {
            @Override
            public void run() {
                // We use MATCH_UNINSTALLED_PACKAGES as the app can be on SD card as well.
                int uninstalled = android.os.Build.VERSION.SDK_INT >= 24 ? PackageManager.MATCH_UNINSTALLED_PACKAGES : PackageManager.GET_UNINSTALLED_PACKAGES;

                boolean uninstallSuccessful = LauncherAppsCompat.getInstance(launcher)
                        .getApplicationInfo(cn.getPackageName(),
                                uninstalled, user) == null;
                callback.onDragObjectRemoved(uninstallSuccessful);
            }
        };
        launcher.addOnResumeCallback(checkIfUninstallWasSuccess);
    } else {
        callback.onDragObjectRemoved(false);
    }
}
 
Example 3
Project: LaunchEnr   File: WidgetPreviewLoader.java   View Source Code Vote up 6 votes
/**
 * @return an array of containing versionCode and lastUpdatedTime for the package.
 */
@Thunk private long[] getPackageVersion(String packageName) {
    synchronized (mPackageVersions) {
        long[] versions = mPackageVersions.get(packageName);
        if (versions == null) {
            versions = new long[2];
            try {

                int uninstalled = android.os.Build.VERSION.SDK_INT >= 24 ? PackageManager.MATCH_UNINSTALLED_PACKAGES : PackageManager.GET_UNINSTALLED_PACKAGES;

                PackageInfo info = mContext.getPackageManager().getPackageInfo(packageName, uninstalled);
                versions[0] = info.versionCode;
                versions[1] = info.lastUpdateTime;
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }
            mPackageVersions.put(packageName, versions);
        }
        return versions;
    }
}
 
Example 4
Project: LaunchEnr   File: IconCache.java   View Source Code Vote up 6 votes
/**
 * Updates the entries related to the given package in memory and persistent DB.
 */
public synchronized void updateIconsForPkg(String packageName, UserHandle user) {
    removeIconsForPkg(packageName, user);
    try {
        int uninstalled = android.os.Build.VERSION.SDK_INT >= 24 ? PackageManager.MATCH_UNINSTALLED_PACKAGES : PackageManager.GET_UNINSTALLED_PACKAGES;

        PackageInfo info = mPackageManager.getPackageInfo(packageName,
                uninstalled);
        long userSerial = mUserManager.getSerialNumberForUser(user);
        for (LauncherActivityInfo app : mLauncherApps.getActivityList(packageName, user)) {
            addIconToDBAndMemCache(app, info, userSerial, false /*replace existing*/);
        }
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return;
    }
}
 
Example 5
Project: LaunchEnr   File: IconCache.java   View Source Code Vote up 4 votes
/**
 * Gets an entry for the package, which can be used as a fallback entry for various components.
 * This method is not thread safe, it must be called from a synchronized method.
 */
private CacheEntry getEntryForPackageLocked(String packageName, UserHandle user,
        boolean useLowResIcon) {
    ComponentKey cacheKey = getPackageKey(packageName, user);
    CacheEntry entry = mCache.get(cacheKey);

    if (entry == null || (entry.isLowResIcon && !useLowResIcon)) {
        entry = new CacheEntry();
        boolean entryUpdated = true;

        // Check the DB first.
        if (!getEntryFromDB(cacheKey, entry, useLowResIcon)) {
            try {
                int uninstalled = android.os.Build.VERSION.SDK_INT >= 24 ? PackageManager.MATCH_UNINSTALLED_PACKAGES : PackageManager.GET_UNINSTALLED_PACKAGES;
                int flags = Process.myUserHandle().equals(user) ? 0 : uninstalled;
                PackageInfo info = mPackageManager.getPackageInfo(packageName, flags);
                ApplicationInfo appInfo = info.applicationInfo;
                if (appInfo == null) {
                    throw new NameNotFoundException("ApplicationInfo is null");
                }

                // Load the full res icon for the application, but if useLowResIcon is set, then
                // only keep the low resolution icon instead of the larger full-sized icon
                Bitmap icon = LauncherIcons.createBadgedIconBitmap(
                        appInfo.loadIcon(mPackageManager), user, mContext, appInfo.targetSdkVersion);
                Bitmap lowResIcon =  generateLowResIcon(icon, mPackageBgColor);
                entry.title = appInfo.loadLabel(mPackageManager);
                entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
                entry.icon = useLowResIcon ? lowResIcon : icon;
                entry.isLowResIcon = useLowResIcon;

                // Add the icon in the DB here, since these do not get written during
                // package updates.
                ContentValues values =
                        newContentValues(icon, lowResIcon, entry.title.toString(), packageName);
                addIconToDB(values, cacheKey.componentName, info,
                        mUserManager.getSerialNumberForUser(user));

            } catch (NameNotFoundException e) {
                e.printStackTrace();
                entryUpdated = false;
            }
        }

        // Only add a filled-out entry to the cache
        if (entryUpdated) {
            mCache.put(cacheKey, entry);
        }
    }
    return entry;
}